From c95de8bc02b6e6d57f7ae59dcaaa49eedde1fefc Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 17 Jul 2015 23:15:45 +0200 Subject: reading from websockets is required diff --git a/src/helsinki.at/rhrdtime/rhrdtime.go b/src/helsinki.at/rhrdtime/rhrdtime.go index fdbdea5..9590e4a 100644 --- a/src/helsinki.at/rhrdtime/rhrdtime.go +++ b/src/helsinki.at/rhrdtime/rhrdtime.go @@ -82,7 +82,7 @@ func getTimeUpdate() []byte { return update_json } -func goTalkWithClient(w http.ResponseWriter, r *http.Request, ps *pubsub.PubSub) { +func handleTimeUpdateClient(w http.ResponseWriter, r *http.Request, ps *pubsub.PubSub) { ws, err := websocket.Upgrade(w, r, nil, 1024, 1024) if _, ok := err.(websocket.HandshakeError); ok { http.Error(w, "Not a websocket handshake", 400) @@ -93,6 +93,15 @@ func goTalkWithClient(w http.ResponseWriter, r *http.Request, ps *pubsub.PubSub) } fmt.Println("Client connected", ws.RemoteAddr()) + go func() { + for { + if _, _, err := ws.NextReader(); err != nil { + ws.Close() + break + } + } + }() + timeupdate_chan := ps.Sub("timeupdate") defer ps.Unsub(timeupdate_chan, "timeupdate") @@ -111,7 +120,7 @@ func goTalkWithClient(w http.ResponseWriter, r *http.Request, ps *pubsub.PubSub) func RunMartini(ps *pubsub.PubSub, addr string) { m := martini.Classic() m.Get("/time", func(w http.ResponseWriter, r *http.Request) { - goTalkWithClient(w, r, ps) + handleTimeUpdateClient(w, r, ps) }) m.RunOnAddr(addr) -- cgit v0.10.2