Operations :通过请求(request)和响应(response)调用远程程序,它是我们的术语远程调用。
就是在服务器端实现的方法在客户端被调用。operations是运行在服务器端的应用程序。
Events :发送到客户端的消息和通知。和operation不同的是,events来自外部,服务器或者是其他客户端。
客户端通过OnEvent回调函数响应。例如有玩家加入房间,该玩家会发送一个请求使用OpCustom方法来调用operation,并且使用一个Dictionary来传递参数。
peer.OpCustom((
byte
)LiteOpCode.RaiseEvent, opParams,
true
);
房间里面的其他玩家会
接受到一个事件
Dictionary<Byte, Object>opParams =
new
Dictionary<Byte,Object>();
opParams[(
byte
)LiteOpKey.GameId] =
"MyRoomName"
;
peer.OpCustom((
byte
)LiteOpCode.Join, opParams,
true
);
注释:
当statuscode == StatusCode.Connect 时调用peer.Opcustom。
创建一个hashtable(opParams),里面包含了参数。调用peer.OpCustom,参数(OperationCode和OperationParams)。
本文介绍了远程调用(operations)的基本概念及其在客户端和服务端之间的交互方式,并详细阐述了如何通过OpCustom方法进行远程调用及参数传递过程。同时,文章还探讨了事件(events)的概念,解释了客户端如何通过OnEvent回调函数接收并响应来自服务器或其他客户端的通知。

929





