55
66websocket is a minimal and idiomatic WebSocket library for Go.
77
8- > ** note** : I haven't been responsive for questions/reports on the issue tracker but I do
9- > read through and there are no outstanding bugs. There are certainly some nice to haves
10- > that I should merge in/figure out but nothing critical. I haven't given up on adding new
11- > features and cleaning up the code further, just been busy. Should anything critical
12- > arise, I will fix it.
13-
148## Install
159
16- ``` bash
10+ ``` sh
1711go get nhooyr.io/websocket
1812```
1913
@@ -23,18 +17,23 @@ go get nhooyr.io/websocket
2317- First class [ context.Context] ( https://blog.golang.org/context ) support
2418- Fully passes the WebSocket [ autobahn-testsuite] ( https://github.com/crossbario/autobahn-testsuite )
2519- [ Zero dependencies] ( https://pkg.go.dev/nhooyr.io/websocket?tab=imports )
26- - JSON and protobuf helpers in the [ wsjson] ( https://pkg.go.dev/nhooyr.io/websocket/wsjson ) and [ wspb ] ( https://pkg.go.dev/nhooyr.io/websocket/wspb ) subpackages
20+ - JSON helpers in the [ wsjson] ( https://pkg.go.dev/nhooyr.io/websocket/wsjson ) subpackage
2721- Zero alloc reads and writes
2822- Concurrent writes
2923- [ Close handshake] ( https://pkg.go.dev/nhooyr.io/websocket#Conn.Close )
3024- [ net.Conn] ( https://pkg.go.dev/nhooyr.io/websocket#NetConn ) wrapper
3125- [ Ping pong] ( https://pkg.go.dev/nhooyr.io/websocket#Conn.Ping ) API
3226- [ RFC 7692] ( https://tools.ietf.org/html/rfc7692 ) permessage-deflate compression
27+ - [ CloseRead] ( https://pkg.go.dev/nhooyr.io/websocket#Conn.CloseRead ) helper for write only connections
3328- Compile to [ Wasm] ( https://pkg.go.dev/nhooyr.io/websocket#hdr-Wasm )
3429
3530## Roadmap
3631
32+ - [ ] Ping pong heartbeat helper [ #267 ] ( https://github.com/nhooyr/websocket/issues/267 )
33+ - [ ] Graceful shutdown helper [ #209 ] ( https://github.com/nhooyr/websocket/issues/209 )
34+ - [ ] Assembly for WebSocket masking [ #16 ] ( https://github.com/nhooyr/websocket/issues/16 )
3735- [ ] HTTP/2 [ #4 ] ( https://github.com/nhooyr/websocket/issues/4 )
36+ - [ ] The holy grail [ #402 ] ( https://github.com/nhooyr/websocket/issues/402 )
3837
3938## Examples
4039
@@ -51,7 +50,7 @@ http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
5150 if err != nil {
5251 // ...
5352 }
54- defer c.Close (websocket. StatusInternalError , " the sky is falling " )
53+ defer c.CloseNow ( )
5554
5655 ctx , cancel := context.WithTimeout (r.Context (), time.Second *10 )
5756 defer cancel ()
@@ -78,7 +77,7 @@ c, _, err := websocket.Dial(ctx, "ws://localhost:8080", nil)
7877if err != nil {
7978 // ...
8079}
81- defer c.Close (websocket. StatusInternalError , " the sky is falling " )
80+ defer c.CloseNow ( )
8281
8382err = wsjson.Write (ctx, c, " hi" )
8483if err != nil {
@@ -110,12 +109,14 @@ Advantages of nhooyr.io/websocket:
110109 - Gorilla writes directly to a net.Conn and so duplicates features of net/http.Client.
111110- Concurrent writes
112111- Close handshake ([ gorilla/websocket #448 ] ( https://github.com/gorilla/websocket/issues/448 ) )
112+ - [ CloseRead] ( https://pkg.go.dev/nhooyr.io/websocket#Conn.CloseRead ) helper for write only connections
113113- Idiomatic [ ping pong] ( https://pkg.go.dev/nhooyr.io/websocket#Conn.Ping ) API
114114 - Gorilla requires registering a pong callback before sending a Ping
115115- Can target Wasm ([ gorilla/websocket #432 ] ( https://github.com/gorilla/websocket/issues/432 ) )
116- - Transparent message buffer reuse with [ wsjson] ( https://pkg.go.dev/nhooyr.io/websocket/wsjson ) and [ wspb ] ( https://pkg.go.dev/nhooyr.io/websocket/wspb ) subpackages
116+ - Transparent message buffer reuse with [ wsjson] ( https://pkg.go.dev/nhooyr.io/websocket/wsjson ) subpackage
117117- [ 1.75x] ( https://github.com/nhooyr/websocket/releases/tag/v1.7.4 ) faster WebSocket masking implementation in pure Go
118118 - Gorilla's implementation is slower and uses [ unsafe] ( https://golang.org/pkg/unsafe/ ) .
119+ Soon we'll have assembly and be 4.5x faster [ #326 ] ( https://github.com/nhooyr/websocket/pull/326 )
119120- Full [ permessage-deflate] ( https://tools.ietf.org/html/rfc7692 ) compression extension support
120121 - Gorilla only supports no context takeover mode
121122- [ CloseRead] ( https://pkg.go.dev/nhooyr.io/websocket#Conn.CloseRead ) helper ([ gorilla/websocket #492 ] ( https://github.com/gorilla/websocket/issues/492 ) )
0 commit comments