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.
127
+
which makes it easy to use correctly.
133
128
134
129
Furthermore, nhooyr/websocket has support for newer Go idioms such as context.Context and
135
130
also uses net/http's Client and ResponseWriter directly for WebSocket handshakes.
136
131
gorilla/websocket writes its handshakes directly to a net.Conn which means
137
132
it has to reinvent hooks for TLS and proxying and prevents support of HTTP/2.
138
133
134
+
Another advantage of nhooyr/websocket is that it supports multiple concurrent writers out
135
+
of the box.
136
+
139
137
### x/net/websocket
140
138
141
139
https://godoc.org/golang.org/x/net/websocket
@@ -149,12 +147,12 @@ See https://github.com/golang/go/issues/18152
149
147
https://github.com/gobwas/ws
150
148
151
149
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.
150
+
and clarity.
153
151
154
152
This library is fantastic in terms of performance. The author put in significant
155
153
effort to ensure its speed and I have applied as many of its optimizations as
156
-
I could into nhooyr/websocket.
154
+
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
155
158
156
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.
157
+
but for most users, the API provided by nhooyr/websocket will fit better as it is just as
158
+
performant but much easier to use correctly and idiomatic.
0 commit comments