summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/helsinki.at/rhrdtime/rhrdtime.go13
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)