I would like to be able to respond "pong" when I get "ping" for the keep alive connection on golang.org/x/websocket
impl.
It seems that it's not supported natively. Is it possible to implement it? How to proceed?
srv := &http.Server{
Addr: ":3000",
ReadTimeout: 12 * time.Second,
IdleTimeout: 12 * time.Second,
WriteTimeout: 12 * time.Second,
ReadHeaderTimeout: 12 * time.Second,
}
http.Handle("/websocket", websocket.Handler(handler))
CodePudding user response:
The golang.org/x/net/websocket package automatically responds to a PING message with a PONG message. Application code is not required to enable the feature.
View the code here.