Giter VIP home page Giter VIP logo

sproto-unity's Introduction

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);

sproto-unity's People

Contributors

m2q1n9 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

sproto-unity's Issues

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之后,服务器会一直发心跳包,当然也许心跳包是需要回复的。
另外一个例子,玩家上线之后,服务器把玩家的金钱发给他,这也是需要回应的,明显不合理啊

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.