Ejemplo n.º 1
0
        public void Send(uint pid, object req, uint connId, Type rspType,
                         ProtocolListener listener, ErrorListener errorListener)
        {
            //regist rspType
            if (rspType != null)
            {
                Register(pid + 1, rspType);
            }

            //record listner
            uint index = 0;

            if (listener != null || errorListener != null)
            {
                index = ++m_index;

                PTLListenerHelper helper = new PTLListenerHelper();
                helper.listener      = listener;
                helper.errorListener = errorListener;
                helper.timestamp     = UnityEngine.Time.realtimeSinceStartup;
                helper.pid           = pid + 1;//this is a rule
                helper.index         = index;

                m_lstRspListener.Add(helper);
            }

            //serialize protocol
            byte[] dataBuffer = SerializeProtocol(req);

            //protocol header
            ProtocolHeader head = new ProtocolHeader();

            head.pid      = pid;
            head.index    = index;
            head.dataSize = dataBuffer.Length;
            head.checksum = SGFEncoder.CheckSum(dataBuffer, dataBuffer.Length);

            //serilize protocol header
            m_sendBufferTemp.Position = 0;
            head.Serialize(m_sendBufferTemp);

            //combine buffer of the protocol
            m_sendBufferTemp.AddBytes(dataBuffer);

            ConnectManager.Instance.Send(connId, m_sendBufferTemp.GetBytes(), m_sendBufferTemp.Length);
        }
Ejemplo n.º 2
0
        public void Send(uint pid, object req, uint connId, Type rspType,
                         ProtocolListener listener, ErrorListener errorListener)
        {
            //注册Rsp类
            if (rspType != null)
            {
                Register(pid + 1, rspType);
            }

            //记录Listener
            uint index = 0;

            if (listener != null || errorListener != null)
            {
                index = ++m_index;

                PTLListenerHelper helper = new PTLListenerHelper();
                helper.listener      = listener;
                helper.errorListener = errorListener;
                helper.timestamp     = UnityEngine.Time.realtimeSinceStartup;
                helper.pid           = pid + 1;//这是一个规则
                helper.index         = index;

                m_lstRspListener.Add(helper);
            }

            //序列化协议数据
            byte[] dataBuffer = SerializeProtocol(req);

            //协议头
            ProtocolHead head = new ProtocolHead();

            head.pid      = pid;
            head.index    = index;
            head.dataSize = dataBuffer.Length;
            head.checksum = SGFEncoding.CheckSum(dataBuffer, dataBuffer.Length);

            //序列化协议头
            m_sendBufferTemp.Position = 0;
            head.Serialize(m_sendBufferTemp);

            //组合整个协议Buffer
            m_sendBufferTemp.AddBytes(dataBuffer);

            ConnectManager.Instance.Send(connId, m_sendBufferTemp.GetBytes(), m_sendBufferTemp.Length);
        }