Download the attachment , export to you go/src/ . you need to run cd webgame/server/message && go get
cd gameai and go build in the folder ,.
1. ./gameai &
2. go test -v
after 100000 circulations :
panic: bytes.Buffer: truncation out of range
goroutine 29 [running]:
bytes.(*Buffer).Truncate(0xc20069aee0, 0x02013/05/2)
/usr/local/go11/src/pkg/bytes/buffer.go:65 +0xc7
bytes.(*Buffer).Read(0xc20069aee0, 0xc2007267a2, 0x2, 0x6, 0x0, ...)
/usr/local/go11/src/pkg/bytes/buffer.go:255 +0x6c
io.ReadAtLeast(0xc2000fb1b0, 0xc20069aee0, 0xc2007267a0, 0x4, 0x8, ...)
/usr/local/go11/src/pkg/io/io.go:284 +0xf7
io.ReadFull(0xc2000fb1b0, 0xc20069aee0, 0xc2007267a0, 0x4, 0x8, ...)
/usr/local/go11/src/pkg/io/io.go:302 +0x6f
encoding/binary.Read(0xc2000fb1b0, 0xc20069aee0, 0xc200151c60, 0x3d, 0x217980, ...)
/usr/local/go11/src/pkg/encoding/binary/binary.go:136 +0xf2
webgame/server/gamelib.func·002(0xc20014ecb0, 0xc20014e955, 0x22, 0x3f)
/Users/gao/code/mygo/src/webgame/server/gamelib/server.go:37 +0x2ab
webgame/server/gamelib.(*ServerMex).connDataSplit(0xc2000bf9b0)
/Users/gao/code/mygo/src/webgame/server/gamelib/server.go:129 +0x40a
created by webgame/server/gamelib.(*ServerMex).RunServer
/Users/gao/code/mygo/src/webgame/server/gamelib/server.go:180 +0xa4
goroutine 1 [IO wait]:
net.runtime_pollWait(0x5fde60, 0x72, 0x0)
/usr/local/go11/src/pkg/runtime/znetpoll_darwin_amd64.c:118 +0x82
net.(*pollDesc).WaitRead(0xc2000d42c0, 0x23, 0xc2000fb690)
/usr/local/go11/src/pkg/net/fd_poll_runtime.go:75 +0x31
net.(*netFD).accept(0xc2000d4240, 0x38bc90, 0x0, 0xc2000fb690, 0x23, ...)
/usr/local/go11/src/pkg/net/fd_unix.go:385 +0x2c1
net.(*TCPListener).AcceptTCP(0xc200159068, 0x3032d, 0x750ec8, 0x3032d)
/usr/local/go11/src/pkg/net/tcpsock_posix.go:229 +0x45
net.(*TCPListener).Accept(0xc200159068, 0xc20014ecb0, 0xc20014ecb0, 0xc20014ecb0, 0x0, ...)
/usr/local/go11/src/pkg/net/tcpsock_posix.go:239 +0x25
webgame/server/gamelib.(*ServerMex).RunServer(0xc2000bf9b0, 0xc2000fb2a0, 0x2, 0x5, 0xc2000fb2a0, ...)
/Users/gao/code/mygo/src/webgame/server/gamelib/server.go:185 +0x113
main.main()
/Users/gao/code/mygo/src/webgame1111/server/gameai/server.go:36 +0x90
goroutine 2 [syscall]:
but but but but but but but !!!! well I can assure you there is always a method to my madness.
gamelib/server.go in line 33 ,
},
HEAD_14B: func(r *Request, b []byte) {
if len(b) < 14 {
return
}
Log.Println(b) // Now … the pain not exists!
buf := bytes.NewBuffer(b)
tbuf = bytes.NewBuffer(buf.Next(2))
binary.Read(tbuf, binary.BigEndian, &r.Cid)
tbuf = bytes.NewBuffer(buf.Next(4))
binary.Read(tbuf, binary.BigEndian, &r.Rid)
tbuf = bytes.NewBuffer(buf.Next(4))
binary.Read(tbuf, binary.BigEndian, &r.Uid)
tbuf = bytes.NewBuffer(buf.Next(2))
binary.Read(tbuf, binary.BigEndian, &r.Typ)
tbuf = bytes.NewBuffer(buf.Next(2))
binary.Read(tbuf, binary.BigEndian, &r.Mlen)
r.Msg = buf.Next(int(r.Mlen))
},
My system ……
Darwin gaomatoMacBook-Air.local 12.3.0 Darwin Kernel Version 12.3.0: Sun Jan 6 22:37:10 PST 2013; root:xnu-2050.22.13~1/RELEASE_X86_64 x86_64