Sproto Unity

by m2q1n9
+

A demo show how to use sproto-Csharp in Unity.

( Updated 15 minutes ago )

sproto-Unity

A demo show how to use sproto-Csharp in Unity.

How to send RPC

SprotoType.Handshake.request req = new SprotoType.Handshake.request();
req.uid = uid;
req.token = token;

NetSender.Send<Protocol.Handshake>(req, (_) =>
{
    SprotoType.Handshake.response rsp = _ as SprotoType.Handshake.response;
    if (rsp.result == 0)
    {
    }
});

How to recv RPC

SprotoTypeBase HeartbeatRsp(SprotoTypeBase _)
{
    SprotoType.Heartbeat.request req = _ as SprotoType.Heartbeat.request;
    return null; // can return a response
}

NetReceiver.AddHandler<Protocol.Heartbeat>(HeartbeatRsp);