-
Notifications
You must be signed in to change notification settings - Fork 198
Open
Description
type Args struct {
A, B int
}
type Request struct {
ID uint64
Method string
}
// msgp EncodeMsg & DecodeMsg done.client.go
func main() {
conn, err := net.Dial("tcp", "127.0.0.1:1234")
if err != nil {
log.Fatal("dialing:", err)
}
ids := Request{1, "Arith.Divide"}
args := Args{int('z'), int('a')}
args2 := Args{int('x'), int('i')}
msgp.Encode(conn, ids)
// log.Println("hai") // If this is valid, the server's result is ok.
msgp.Encode(conn, args)
msgp.Encode(conn, args2)
}server.go
func main() {
l, e := net.Listen("tcp", ":1234")
if e != nil {
log.Fatal("listen error:", e)
}
fmt.Println("start listen for client...")
for {
conn, err := l.Accept()
if err != nil {
log.Print("rpcjs.Serve: accept:", err.Error())
return
}
var req Request
var arg Args
var arg2 Args
msgp.Decode(conn, &req)
fmt.Println(req)
msgp.Decode(conn, &arg)
fmt.Println(arg)
msgp.Decode(conn, &arg2)
fmt.Println(arg2)
}
}// Output: client first run
{1 Arith.Divide}
{0 0} or {120 105} or {122 97}
{0 0}
// Output: client second run
{1 Arith.Divide}
{122 97}
{0 0}
why?
when the log.Println("hai") is valid, the calls is ok.
// Output:
{1 Arith.Divide}
{122 97}
{120 105}
Metadata
Metadata
Assignees
Labels
No labels