()
| 10 | ) |
| 11 | |
| 12 | func clientAsyncRPC() { |
| 13 | // 等待服务器返回数据 |
| 14 | done := make(chan struct{}) |
| 15 | |
| 16 | queue := cellnet.NewEventQueue() |
| 17 | |
| 18 | p := peer.NewGenericPeer("tcp.Connector", "async rpc", peerAddress, queue) |
| 19 | |
| 20 | // 创建一个消息同步接收器 |
| 21 | rv := proc.NewSyncReceiver(p) |
| 22 | |
| 23 | proc.BindProcessorHandler(p, "tcp.ltv", rv.EventCallback()) |
| 24 | |
| 25 | p.Start() |
| 26 | |
| 27 | queue.StartLoop() |
| 28 | |
| 29 | // 等连接上时 |
| 30 | rv.WaitMessage("cellnet.SessionConnected") |
| 31 | |
| 32 | // 异步RPC |
| 33 | rpc.Call(p, &TestEchoACK{ |
| 34 | Msg: "hello", |
| 35 | Value: 1234, |
| 36 | }, time.Second, func(raw interface{}) { |
| 37 | |
| 38 | switch result := raw.(type) { |
| 39 | case error: |
| 40 | fmt.Println(result) |
| 41 | default: |
| 42 | fmt.Println(result) |
| 43 | done <- struct{}{} |
| 44 | } |
| 45 | |
| 46 | }) |
| 47 | |
| 48 | // 等待客户端收到消息 |
| 49 | <-done |
| 50 | } |
no test coverage detected