예제 #1
0
        private void DoReceiveInMain()
        {
            lock (recvBufferQueue)
            {
                if (recvBufferQueue.Count > 0)
                {
                    byte[] buffer = recvBufferQueue.Dequeue();

                    IPCMessage msg = ProtoBuffUtility.Deserialize<IPCMessage>(buffer);
                    HandleMessage(msg);
                }
            }
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
0
 private void HandleMessage(IPCMessage msg)
 {
     RPCMessage rpcmsg = msg.rpcMessage;
     var helper = rpcManager.GetMethodHelper(rpcmsg.name);
     if (helper != null)
     {
         object[] args  = new object[rpcmsg.args.Length +1];
         List<RPCArg> rawargs = rpcmsg.rawargs;
         ParameterInfo[] paramInfo = helper.method.GetParameters();
         if (args.Length == paramInfo.Length)
         {
             for (int i = 0; i < rawargs.Count; i++)
             {
                 if (rawargs[i].type == enRPCArgType.PBObject)
                 {
                     args[i + 1] = ProtoBuffUtility.Deserialize(paramInfo[i + 1].ParameterType, rawargs[i].rawValue);
                 }
                 else
                 {
                     args[i + 1] = rawargs[i].value;
                 }
             }
             args[0] = msg.srcID;
             currInvokingName = rpcmsg.name;
             currInvokingSrc = msg.srcID;
             try
             {
                 helper.method.Invoke(helper.listener, BindingFlags.NonPublic, null, args, null);
             }
             catch (Exception e)
             {
                 Debuger.LogError("RPC调用出错:{0}\n{1}", e.Message, e.StackTrace);
             }
             currInvokingName = "";
             currInvokingSrc = 0;
         }
         else
         {
             Debuger.LogWarning("参数数量不一致!");
         }
     }
     else
     {
         Debuger.LogWarning("RPC不存在!");
     }
 }
예제 #5
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);
        }