Example #1
0
        private void Send(int reqId, int resId, byte[] content, Action <int, ProtoPacket> callback)
        {
            //todo check network

            if (resId != 0)
            {
                //previous req is override, notify error
                if (mIdToOnceHandler.TryGetValue(resId, out var delegateObj))
                {
                    var error = ProtoPacket.CreateError(resId, (int)ErrorCode.req_override, string.Empty);
                    if (delegateObj != null)
                    {
                        delegateObj.DynamicInvoke(resId, error);
                    }
                    mIdToOnceHandler.Remove(resId);
                }

                if (callback != null)
                {
                    AddToHandler(resId, callback, mIdToOnceHandler);
                }

                var reqRecord = new ReqRecord();
                reqRecord.reqId   = reqId;
                reqRecord.resId   = resId;
                reqRecord.reqTime = Time.realtimeSinceStartup;
                mIdToRecord.Add(resId, reqRecord);
            }

            mChannel.Send(SendBuf.From(DCGameProtocol.GetIntBuf(reqId)), SendBuf.From(content));
        }
Example #2
0
        public void OnSend()
        {
            var req     = new PTestDemoClsReq();
            var reqId   = DCGameProtocol.GetId(req);
            var content = req.ToByteArray();

            mChannel.Send(SendBuf.From(DCGameProtocol.GetIntBuf(reqId)), SendBuf.From(content));
//            mChannel.Send(Encoding.UTF8.GetBytes(mSendStr));
        }