From 59e7057fe961ec69fef1c634e961a711c50eed39 Mon Sep 17 00:00:00 2001 From: "rui.zheng" Date: Mon, 11 Jan 2016 11:31:23 +0800 Subject: [PATCH] fix websocket crash --- ws.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ws.go b/ws.go index dafb42c..c5fc21d 100644 --- a/ws.go +++ b/ws.go @@ -129,15 +129,18 @@ func (s *ws) handle(w http.ResponseWriter, r *http.Request) { } func (s *ws) ListenAndServe() error { - http.HandleFunc("/ws", s.handle) - return http.ListenAndServe(s.arg.Addr, nil) + sm := http.NewServeMux() + sm.HandleFunc("/ws", s.handle) + return http.ListenAndServe(s.arg.Addr, sm) } func (s *ws) listenAndServeTLS() error { - http.HandleFunc("/ws", s.handle) + sm := http.NewServeMux() + sm.HandleFunc("/ws", s.handle) server := &http.Server{ Addr: s.arg.Addr, TLSConfig: &tls.Config{Certificates: []tls.Certificate{s.arg.Cert}}, + Handler: sm, } return server.ListenAndServeTLS("", "") }