MCPcopy
hub / github.com/davyxu/cellnet / clientAsyncRPC

Function clientAsyncRPC

examples/echo/client_rpc_async.go:12–50  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10)
11
12func 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}

Callers 1

mainFunction · 0.85

Calls 9

EventCallbackMethod · 0.95
StartLoopMethod · 0.95
WaitMessageMethod · 0.95
NewEventQueueFunction · 0.92
NewGenericPeerFunction · 0.92
NewSyncReceiverFunction · 0.92
BindProcessorHandlerFunction · 0.92
CallFunction · 0.92
StartMethod · 0.65

Tested by

no test coverage detected