From 4d0c9da4d9b826cea14c3805e41e6ac4c0be60bd Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Mon, 2 May 2022 14:48:45 -0700 Subject: [PATCH] Add comments for ServeWS --- server/server.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/server.go b/server/server.go index 234c682..6a06843 100644 --- a/server/server.go +++ b/server/server.go @@ -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)) }