Add comments for ServeWS

This commit is contained in:
Elara 2022-05-02 14:48:45 -07:00
parent a0d167ff75
commit 4d0c9da4d9
1 changed files with 6 additions and 0 deletions

View File

@ -258,17 +258,23 @@ func (s *Server) Serve(ln net.Listener, cf codec.CodecFunc) {
}
}
// ServeWS starts a server using WebSocket. This may be useful for
// clients written in other languages, such as JS for a browser.
func (s *Server) ServeWS(addr string, cf codec.CodecFunc) (err error) {
// Create new WebSocket server
ws := websocket.Server{}
// Create new WebSocket config
ws.Config = websocket.Config{
Version: websocket.ProtocolVersionHybi13,
}
// Set server handler
ws.Handler = func(c *websocket.Conn) {
s.handleConn(cf(c))
}
// Listen and serve on given address
return http.ListenAndServe(addr, http.HandlerFunc(ws.ServeHTTP))
}