diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-07-17 21:15:45 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-07-17 21:15:45 (GMT) |
commit | c95de8bc02b6e6d57f7ae59dcaaa49eedde1fefc (patch) | |
tree | 54b280340d83bc49f518fe11f5a704d2c04ab522 /src/helsinki.at/rhrdtime | |
parent | 680c14befd7bbba93cc6603b6ede65791bfa9eab (diff) |
reading from websockets is required
Diffstat (limited to 'src/helsinki.at/rhrdtime')
-rw-r--r-- | src/helsinki.at/rhrdtime/rhrdtime.go | 13 |
1 files changed, 11 insertions, 2 deletions
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) |