예제 #1
0
        public void Invoke(string name, params object[] args)
        {
            RPCMessage rpcmsg = new RPCMessage
            {
                name = name,
                args = args
            };

            byte[] buffer = ProtoBuffUtility.Serialize(rpcmsg);

            NetMessage msg = new NetMessage
            {
                Head = new ProtocolHead
                {
                    uid      = uid,
                    dataSize = (ushort)buffer.Length
                },
                content = buffer
            };

            byte[] tmp = null;
            int    len = msg.Serialize(out tmp);

            connection.Send(tmp, len);
        }
예제 #2
0
        public void Return(params object[] args)
        {
            if (connection != null)
            {
                var        name   = "On" + currInvokingName;
                RPCMessage rpcmsg = new RPCMessage
                {
                    name = name,
                    args = args
                };
                byte[] buffer = ProtoBuffUtility.Serialize(rpcmsg);

                NetMessage msg = new NetMessage
                {
                    Head = new ProtocolHead
                    {
                        uid      = uid,
                        dataSize = (ushort)buffer.Length
                    },
                    content = buffer
                };

                byte[] tmp = null;
                int    len = msg.Serialize(out tmp);
                connection.Send(tmp, len);
            }
        }
예제 #3
0
        public void Invoke(ISession[] listSession, string name, params object[] args)
        {
            RPCMessage rpcmsg = new RPCMessage
            {
                name = name,
                args = args
            };

            byte[] buffer = ProtoBuffUtility.Serialize(rpcmsg);

            NetMessage msg = new NetMessage
            {
                Head = new ProtocolHead {
                    dataSize = (ushort)buffer.Length
                },
                content = buffer
            };

            byte[] tmp = null;
            int    len = msg.Serialize(out tmp);

            foreach (ISession session in listSession)
            {
                session.Send(tmp, len);
            }
        }
예제 #4
0
        public bool Send(FSPFrameData frame)
        {
            if (!IsActived())
            {
                Debuger.LogWarning("Session已经不活跃了!");
                return(false);
            }

            tempSendData.frame = frame;
            int len = ProtoBuffUtility.Serialize(tempSendData, sendBufferTemp);

            return(kcp.Send(sendBufferTemp, len) == 0);
        }
예제 #5
0
 public bool SendFSP(int clientFrameID, int cmd, int[] args)
 {
     if (isRunning)
     {
         FSPMessage msg = tempSendData.msg;
         msg.cmd           = cmd;
         msg.clientFrameID = clientFrameID;
         msg.args          = args;
         int length = ProtoBuffUtility.Serialize(tempSendData, sendBufferTemp);
         kcp.Send(sendBufferTemp, length);
         return(length > 0);
     }
     return(false);
 }
예제 #6
0
        public void Invoke(int dstID, string name, params object[] args)
        {
            RPCMessage rpcmsg = new RPCMessage
            {
                name = name,
                args = args
            };

            IPCMessage msg = new IPCMessage
            {
                srcID = ipcInfo.ID,
                rpcMessage = rpcmsg
            };

            byte[] temp = ProtoBuffUtility.Serialize(msg);
            SendMessage(dstID, temp, temp.Length);
        }
예제 #7
0
        public void ReturnError(string errinfo, int errcode = 1)
        {
            var name = "On" + currInvokingName + "Error";
            RPCMessage rpcmsg = new RPCMessage
            {
                name = name,
                args = new object[] {errinfo, errcode}
            };

            IPCMessage msg = new IPCMessage
            {
                srcID = ipcInfo.ID,
                rpcMessage = rpcmsg
            };
            byte[] temp = ProtoBuffUtility.Serialize(msg);
            SendMessage(currInvokingSrc, temp, temp.Length);
        }
예제 #8
0
        public void Return(params object[] args)
        {
            var name = "On" + currInvokingName;
            RPCMessage rpcmsg = new RPCMessage
            {
                name = name,
                args = args
            };

            IPCMessage msg = new IPCMessage
            {
                srcID = ipcInfo.ID,
                rpcMessage = rpcmsg
            };

            byte[] temp = ProtoBuffUtility.Serialize(msg);
            SendMessage(currInvokingSrc, temp, temp.Length);
        }
예제 #9
0
        public void Send <TReq>(uint cmd, TReq req)
        {
            NetMessage meaasge = new NetMessage
            {
                Head =
                {
                    index =   0,
                    cmd   = cmd,
                    uid   = uid
                },
                content = ProtoBuffUtility.Serialize(req)
            };

            meaasge.Head.dataSize = (ushort)meaasge.content.Length;
            byte[] temp;
            int    len = meaasge.Serialize(out temp);

            connection.Send(temp, len);
        }
예제 #10
0
        public void Send <MsgType>(ISession session, uint index, uint cmd, MsgType msg)
        {
            NetMessage msgobj = new NetMessage
            {
                Head =
                {
                    index = index,
                    cmd   = cmd,
                    uid   = session.uid
                },
                content = ProtoBuffUtility.Serialize(msg)
            };

            msgobj.Head.dataSize = (ushort)msgobj.content.Length;

            byte[] tmp;
            int    len = msgobj.Serialize(out tmp);

            session.Send(tmp, len);
        }
예제 #11
0
        //一问一答方式
        public void Send <TReq, TRsp>(uint cmd, TReq req, Action <TRsp> successHandle, float timeOut = 30,
                                      Action <enNetErrorCode> errorHandle = null)
        {
            NetMessage message = new NetMessage
            {
                Head =
                {
                    index = MessageIndexGenerator.GetNextMessageIndex(),
                    cmd   = cmd,
                    uid   = uid
                },
                content = ProtoBuffUtility.Serialize(req)
            };

            message.Head.dataSize = (ushort)message.content.Length;
            byte[] temp;
            int    len = message.Serialize(out temp);

            connection.Send(temp, len);
            AddListener(cmd, successHandle, message.Head.index, timeOut, errorHandle);
        }
예제 #12
0
        public void ReturnError(string errinfo, int errcode = 1)
        {
            var        name   = "On" + currInvokingName + "Error";
            RPCMessage rpcmsg = new RPCMessage
            {
                name = name,
                args = new object[] { errinfo, errcode }
            };

            byte[] buffer = ProtoBuffUtility.Serialize(rpcmsg);

            NetMessage msg = new NetMessage
            {
                Head = new ProtocolHead {
                    dataSize = (ushort)buffer.Length
                },
                content = buffer
            };

            byte[] tmp = null;
            int    len = msg.Serialize(out tmp);

            connection.Send(tmp, len);
        }