Comments (2)
Recoverable timeouts are difficult to implement. I am not aware of other Go network protocol libraries that support recoverable timeouts.
The application can implement timeout polling in a net.Conn shim between the websocket.Conn and the underlying net.Conn. A sketch for creating the shim is:
type appResponseWriter struct { http.ResponseWriter }
func (w appResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
if h, ok := w.ResponseWriter.(http.Hijacker); ok {
c, brw, err := h.Hijack()
c = appConn(c)
return c, brw, err
} else {
return nil, nil, errors.New("not supported")
}
}
type appConn struct {
net.Conn
}
func (c appConn) Read(p []byte) (int, err) {
// implement timeout polling here.
}
func handler(w http.ResponseWriter, r *http.Request) {
ws, err := websocket.Upgrade(appResponseWriter{w}, r, nil, 1024, 1024)
if _, ok := err.(websocket.HandshakeError); ok {
http.Error(w, "Not a websocket handshake", 400)
return
} else if err != nil {
log.Println(err)
return
}
... Use conn to send and receive messages.
}
from websocket.
It is not idiomatic to poll connections with timeouts in Go.
Close the websocket connection one minute after writing the close message. This will cause a blocked reader to return with an error.
from websocket.
Related Issues (20)
- [BUG] websocket: close 1006 (abnormal closure): unexpected EOF HOT 3
- [BUG] Undefined Error When Running go get github.com/gorilla/websocket with Go 1.15.11 Without Enabling GO111MODULE HOT 1
- [BUG] Debug messages are printed to log HOT 2
- [BUG] Getting "websocket: internal error, unexpected bytes at end of flate stream" despite protecting write calls with mutex
- [BUG] websocket on compress close duplicate HOT 7
- Module path not updated to github.com/gorilla/websocket/v2 and new tag does not follow semantic versioning HOT 2
- Websocket ping pong timeout HOT 2
- [BUG] Dialer type registered unconditionally into proxy
- Commits on branch release-1.5 are not useful
- golang.org/x/net is vendored in branch 1.5.1
- [BUG] Potential Handle Leak? HOT 1
- [Question] <traffic from local machine to websocket server is high> HOT 2
- [BUG] 1.5.1: use of closed network connection, 1.5.0 is fine HOT 4
- [BUG] 1.5.1 uses log.Printf HOT 15
- [FEATURE] Provide an override for `isValidChallengeKey` using a custom validator HOT 8
- Memory overflow; using ReadMessage() method
- [BUG] Clients get disconnected due to SetWriteDeadline and large workload HOT 4
- [question] error: RSV1 set, bad opcode 7, bad MASK HOT 10
- concurrent write to websocket connection HOT 2
- Documentation oversight after updating io/ioutl functions to io functions HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from websocket.