server/spectator.go

38 lines
658 B
Go

package main
import (
"code.google.com/p/go.net/websocket"
"log"
)
type Spectator struct {
ws *websocket.Conn
send chan Message
Id string
}
func (s *Spectator) sender() {
log.Printf("%s: sender launched", s.Id)
for things := range s.send {
err := websocket.JSON.Send(s.ws, things)
if err != nil {
break
}
}
s.ws.Close()
log.Printf("%s: spectator sender close", s.Id)
}
func (s *Spectator) recv() {
for {
var msg interface{}
err := websocket.JSON.Receive(s.ws, &msg)
if err != nil {
log.Printf("%s: problem receiving JSON from spectator: %s", s.Id, err)
break
}
}
log.Printf("%s: recv close", s.Id)
s.ws.Close()
}