@@ -110,34 +110,33 @@ https://github.com/gorilla/websocket
110110This package is the community standard but it is 6 years old and over time
111111has accumulated cruft. There are too many ways to do the same thing.
112112Just compare the godoc of
113- [ nhooyr/websocket] ( https://godoc.org/nhooyr.io/websocket ) side by side with
114- [ gorilla/websocket] ( https://godoc.org/github.com/gorilla/websocket ) .
113+ [ nhooyr/websocket] ( https://godoc.org/nhooyr.io/websocket ) with
114+ [ gorilla/websocket] ( https://godoc.org/github.com/gorilla/websocket ) side by side .
115115
116- The API for nhooyr/websocket has been designed such that there is only one way to do things
117- which makes it easy to use correctly. Not only is the API simpler, the implementation is
116+ The API for nhooyr/websocket has been designed such that there is only one way to do things.
117+ This makes it easy to use correctly. Not only is the API simpler, the implementation is
118118only 2200 lines whereas gorilla/websocket is at 3500 lines. That's more code to maintain,
119119more code to test, more code to document and more surface area for bugs.
120120
121- Moreover, nhooyr/websocket has support for newer Go idioms such as context.Context and
122- also uses net/http's Client and ResponseWriter directly for WebSocket handshakes.
123- gorilla/websocket writes its handshakes to the underlying net.Conn which means
124- it has to reinvent hooks for TLS and proxies and prevents support of HTTP/2.
121+ Moreover, nhooyr/websocket supports newer Go idioms such as context.Context.
122+ It also uses net/http's Client and ResponseWriter directly for WebSocket handshakes.
123+ gorilla/websocket writes its handshakes to the underlying net.Conn.
124+ Thus it has to reinvent hooks for TLS and proxies and prevents support of HTTP/2.
125125
126126Some more advantages of nhooyr/websocket are that it supports concurrent writes and
127127makes it very easy to close the connection with a status code and reason.
128128
129129The ping API is also nicer. gorilla/websocket requires registering a pong handler on the Conn
130130which results in awkward control flow. With nhooyr/websocket you use the Ping method on the Conn
131- that sends a ping and also waits for the pong, though you must be reading from the connection
132- for the pong to be read.
131+ that sends a ping and also waits for the pong.
133132
134133Additionally, nhooyr.io/websocket can compile to [ WASM] ( https://godoc.org/nhooyr.io/websocket#hdr-WASM ) for the browser.
135134
136135In terms of performance, the differences mostly depend on your application code. nhooyr/websocket
137136reuses message buffers out of the box if you use the wsjson and wspb subpackages.
138137As mentioned above, nhooyr/websocket also supports concurrent writers.
139138
140- The only performance con to nhooyr/websocket is that uses one extra goroutine to support
139+ The only performance con to nhooyr/websocket is that it uses one extra goroutine to support
141140cancellation with context.Context. This costs 2 KB of memory which is cheap compared to
142141the benefits.
143142
@@ -161,9 +160,9 @@ effort to ensure its speed and I have applied as many of its optimizations as
161160I could into nhooyr/websocket. Definitely check out his fantastic [ blog post] ( https://medium.freecodecamp.org/million-websockets-and-go-cc58418460bb )
162161about performant WebSocket servers.
163162
164- If you want a library that gives you absolute control over everything, this is the library,
165- but for most users, the API provided by nhooyr/websocket will fit better as it is nearly just
166- as performant but much easier to use correctly and idiomatic .
163+ If you want a library that gives you absolute control over everything, this is the library.
164+ But for 99.9% of use cases, nhooyr/websocket will fit better. It's nearly as performant
165+ but much easier to use.
167166
168167## Contributing
169168
0 commit comments