sproto-Unity
sproto-Unity copied to clipboard
NetCore.Send有疑问
Uploading the sproto problem with unity.txt… SProto的wiki写着,如果有type那么消息是一个请求,没有是一个response。在NetCore里我有一个疑惑, int tag = (int)pkg.type; long session = (long)pkg.session;
if (pkg.HasType)
{
// here is obvisual server send some package to me
RpcReqHandler rpcReqHandler = NetReceiver.GetHandler(tag);
if (rpcReqHandler != null)
{
SprotoTypeBase rpcRsp = rpcReqHandler(protocol.GenRequest(tag, data, offset));
if (pkg.HasSession)
{
// why i send it back
Send(rpcRsp, session, tag);
}
}
}
这里是在处理收到的消息,既然是服务器发给客户端的消息,怎么会被称为一个请求呢,然后在后面又Send了一个回应给服务器, 比如当Unity连上skynet之后,服务器会一直发心跳包,当然也许心跳包是需要回复的。 另外一个例子,玩家上线之后,服务器把玩家的金钱发给他,这也是需要回应的,明显不合理啊