You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The API for nhooyr/websocket has been designed such that there is only one way to do things
128
-
which makes using it correctly and safely much easier.
129
-
130
-
In terms of lines of code, this library is around 2000 whereas gorilla/websocket is
131
-
at 7000. So while the API for nhooyr/websocket is simpler, the implementation is also
132
-
significantly simpler and easier to test which reduces the surface are of bugs.
128
+
which makes it easy to use correctly.
133
129
134
130
Furthermore, nhooyr/websocket has support for newer Go idioms such as context.Context and
135
131
also uses net/http's Client and ResponseWriter directly for WebSocket handshakes.
136
132
gorilla/websocket writes its handshakes directly to a net.Conn which means
137
133
it has to reinvent hooks for TLS and proxying and prevents support of HTTP/2.
138
134
135
+
Another advantage of nhooyr/websocket is that it supports multiple concurrent writers out
136
+
of the box.
137
+
139
138
### x/net/websocket
140
139
141
140
https://godoc.org/golang.org/x/net/websocket
@@ -149,12 +148,12 @@ See https://github.com/golang/go/issues/18152
149
148
https://github.com/gobwas/ws
150
149
151
150
This library has an extremely flexible API but that comes at the cost of usability
152
-
and clarity. Its not clear what the best way to do anything is.
151
+
and clarity.
153
152
154
153
This library is fantastic in terms of performance. The author put in significant
155
154
effort to ensure its speed and I have applied as many of its optimizations as
156
-
I could into nhooyr/websocket.
155
+
I could into nhooyr/websocket. Definitely check out his fantastic [blog post](https://medium.freecodecamp.org/million-websockets-and-go-cc58418460bb) about performant WebSocket servers.
157
156
158
157
If you want a library that gives you absolute control over everything, this is the library,
159
-
but for most users, the API provided by nhooyr/websocket will definitely fit better as it will
160
-
be just as performant but much easier to use correctly.
158
+
but for most users, the API provided by nhooyr/websocket will fit better as it is just as
159
+
performant but much easier to use correctly and idiomatic.
0 commit comments