From ad9d6c10261bf890bd7849a52210c7085d364a48 Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Tue, 4 Feb 2014 08:00:15 -0800 Subject: [PATCH] Switched to using json.Encoder and Decoder --- player.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/player.go b/player.go index f79a8c1..0882ffa 100644 --- a/player.go +++ b/player.go @@ -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