@@ -11,21 +11,26 @@ This library is in heavy development.
11
11
## Install
12
12
13
13
``` bash
14
- go get nhooyr.io/websocket@master
14
+ go get nhooyr.io/websocket
15
15
```
16
16
17
17
## Features
18
18
19
- - WebSockets over HTTP/2 support
20
19
- Full support of the WebSocket protocol
21
- - Only depends on the stdlib
22
- - Simple to use because of the minimal API
23
- - Uses the context package for cancellation
24
- - Uses net/http's Client to do WebSocket dials
25
- - Compression of text frames larger than 1024 bytes by default
26
- - Highly optimized where it matters
27
- - WASM support
20
+ - Only depends on stdlib
21
+ - Simple to use
22
+ - context.Context is a first class feature
23
+ - net/http is used for WebSocket dials and upgrades
28
24
- Passes the [ autobahn-testsuite] ( https://github.com/crossbario/autobahn-testsuite )
25
+ - JSON helpers
26
+
27
+ ## Roadmap
28
+
29
+ - [ ] WebSockets over HTTP/2 #4
30
+ - [ ] Deflate extension support #5
31
+ - [ ] More optimization #11
32
+ - [ ] WASM #15
33
+ - [ ] Ping/pongs #1
29
34
30
35
## Example
31
36
@@ -99,11 +104,9 @@ See [example_test.go](example_test.go) for more examples.
99
104
- Minimal API is easier to maintain and for others to learn
100
105
- Context based cancellation is more ergonomic and robust than setting deadlines
101
106
- No pings or pongs because TCP keep alives work fine for HTTP/1.1 and they do not make
102
- sense with HTTP/2
107
+ sense with HTTP/2 (see # 1 )
103
108
- net.Conn is never exposed as WebSocket's over HTTP/2 will not have a net.Conn.
104
109
- Functional options make the API very clean and easy to extend
105
- - Compression is very useful for JSON payloads
106
- - JSON helpers make code terse
107
110
- Using net/http's Client for dialing means we do not have to reinvent dialing hooks
108
111
and configurations. Just pass in a custom net/http client if you want custom dialing.
109
112
@@ -126,6 +129,15 @@ is not clear. Just compare the godoc of
126
129
The API for nhooyr/websocket has been designed such that there is only one way to do things
127
130
which makes using it correctly and safely much easier.
128
131
132
+ In terms of lines of code, this library is around 2000 whereas gorilla/websocket is
133
+ at 7000. So while the API for nhooyr/websocket is simpler, the implementation is also
134
+ significantly simpler and easier to test which reduces the surface are of bugs.
135
+
136
+ Furthermore, nhooyr/websocket has support for newer Go idioms such as context.Context and
137
+ also uses net/http's Client and ResponseWriter directly for WebSocket handshakes.
138
+ gorilla/websocket writes its handshakes directly to a net.Conn which means
139
+ it has to reinvent hooks for TLS and proxying and prevents support of HTTP/2.
140
+
129
141
### x/net/websocket
130
142
131
143
https://godoc.org/golang.org/x/net/websocket
0 commit comments