Browse Source

Switched to using json.Encoder and Decoder

master
Stephen McQuay 6 years ago
parent
commit
ad9d6c1026
1 changed files with 5 additions and 3 deletions
  1. +5
    -3
      player.go

+ 5
- 3
player.go 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

Loading…
Cancel
Save