Switched to using json.Encoder and Decoder

This commit is contained in:
Stephen McQuay 2014-02-04 08:00:15 -08:00
parent bc58ee9165
commit ad9d6c1026

View File

@ -2,6 +2,7 @@ package main
import (
"code.google.com/p/go.net/websocket"
"encoding/json"
"log"
)
@ -16,7 +17,8 @@ type player struct {
func (p *player) sender() {
log.Printf("%s: sender launched", p.Id)
for things := range p.send {
err := websocket.JSON.Send(p.ws, things)
enc := json.NewEncoder(p.ws)
err := enc.Encode(things)
if err != nil {
break
}
@ -30,8 +32,8 @@ func (p *player) recv() {
// XXX: need to mark myself as having received something, also binding
// such action to a particular game turn ID
var msgs map[string]Instruction
err := websocket.JSON.Receive(p.ws, &msgs)
dec := json.NewDecoder(p.ws)
err := dec.Decode(&msgs)
if err != nil {
// TODO: perhaps we could be a bit more precise in the handling of
// this 'error' by selecting on some kill signal channel and this