private void Requeue(NetMsg InMsg)
        {
            InMsg.Reset();

            netMsgQueue.Enqueue(InMsg);
        }
        private NetMsg Dequeue()
        {
            NetMsg topMsg = netMsgQueue.Dequeue();

            return(topMsg);
        }
        private void Enqueue(NetMsg InMsg)
        {
            netMsgQueue.Enqueue(InMsg);

            UpdateMsgState();
        }
예제 #4
0
파일: NetClient.cs 프로젝트: hw233/MUUtil
        public void RevClientServer(byte[] rev)
        {
            NetMsg msg = MessageHelper.Instance.ParserPacket(rev, rev.Length - HEADER_SERVER_LEN, false);

            EventDispatcher.Instance.InsertMsg(msg);
        }
예제 #5
0
파일: NetClient.cs 프로젝트: hw233/MUUtil
 public void SendToClientServer(byte[] rev)
 {
     NetMsg msg = MessageHelper.Instance.ParserPacket(rev, rev.Length - HEADER_SERVER_LEN, false);
     //--MiracleClientServer.Instance.RevClientMsg(msg);
 }
예제 #6
0
파일: NetClient.cs 프로젝트: hw233/MUUtil
        public void RevPacketDeal_WorldServer(int recv)
        {
            if (recv <= 0)
            {
                m_socketclient.Close();
            }

            m_iRcvSerLen += recv;

            if (m_iRcvSerLen <= DefaultBufferSize)
            {
                Buffer.BlockCopy(m_RecvDataBuffer_WorldServer, 0, m_TotalBuffer_WorldServer, m_iRcvSerLen - recv, recv);
                Array.Clear(m_RecvDataBuffer_WorldServer, 0, m_RecvDataBuffer_WorldServer.Length);
                if (m_TotalBuffer_WorldServer.Length > DefaultBufferSize)
                {
                    Buffer.BlockCopy(m_TotalBuffer_WorldServer, 0, m_RecvDataBuffer_WorldServer, 0, m_iRcvSerLen);
                    m_TotalBuffer_WorldServer = new byte[DefaultBufferSize];
                    Buffer.BlockCopy(m_RecvDataBuffer_WorldServer, 0, m_TotalBuffer_WorldServer, 0, m_iRcvSerLen);
                    Array.Clear(m_RecvDataBuffer_WorldServer, 0, m_RecvDataBuffer_WorldServer.Length);
                }
            }
            else//超出长度
            {
                byte[] temp = new byte[m_iRcvSerLen - recv];
                Buffer.BlockCopy(m_TotalBuffer_WorldServer, 0, temp, 0, temp.Length);
                Array.Clear(m_TotalBuffer_WorldServer, 0, m_TotalBuffer_WorldServer.Length);
                m_TotalBuffer_WorldServer = new byte[m_iRcvSerLen];
                Buffer.BlockCopy(temp, 0, m_TotalBuffer_WorldServer, 0, temp.Length);
                Buffer.BlockCopy(m_RecvDataBuffer_WorldServer, 0, m_TotalBuffer_WorldServer, temp.Length, recv);
                Array.Clear(m_RecvDataBuffer_WorldServer, 0, m_RecvDataBuffer_WorldServer.Length);
                temp = null;
            }

            while (true)
            {
                int iPacketLength = OnCheckPacket(ref m_TotalBuffer_WorldServer, m_iRcvSerLen, false); //返回包体的长度

                //包的正常长度
                if (iPacketLength >= 0)
                {
                    //包接受完毕,数据处理
                    NetMsg msg = MessageHelper.Instance.ParserPacket(m_TotalBuffer_WorldServer, iPacketLength, false);
                    EventDispatcher.Instance.InsertMsg(msg);
                    m_iRcvSerLen -= (iPacketLength + HEADER_SERVER_LEN);

                    byte[] bufferData = new byte[m_iRcvSerLen];
                    Buffer.BlockCopy(m_TotalBuffer_WorldServer, iPacketLength + HEADER_SERVER_LEN, bufferData, 0, bufferData.Length);
                    Array.Clear(m_TotalBuffer_WorldServer, 0, m_TotalBuffer_WorldServer.Length);
                    Buffer.BlockCopy(bufferData, 0, m_TotalBuffer_WorldServer, 0, bufferData.Length);

                    //长度为0,包体无内容
                    if (m_iRcvSerLen == 0)
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
        }
예제 #7
0
파일: NetClient.cs 프로젝트: hw233/MUUtil
        public void RevPacketDeal(int recv)
        {
            if (recv <= 0)
            {
                //--MiracleEventCenter.Instance.Publish<MiracleSocketEvt>(null, new MiracleSocketEvt());
                DebugUtil.LogError("Net Error");
                return;
                //throw new Exception("Net Error");
            }

            m_iRcvLength += recv;

            if (m_iRcvLength <= DefaultBufferSize)
            {
                Buffer.BlockCopy(m_RecvDataBuffer, 0, m_TotalBuffer, m_iRcvLength - recv, recv);
                Array.Clear(m_RecvDataBuffer, 0, m_RecvDataBuffer.Length);
                if (m_TotalBuffer.Length > DefaultBufferSize)
                {
                    Buffer.BlockCopy(m_TotalBuffer, 0, m_RecvDataBuffer, 0, m_iRcvLength);
                    m_TotalBuffer = new byte[DefaultBufferSize];
                    Buffer.BlockCopy(m_RecvDataBuffer, 0, m_TotalBuffer, 0, m_iRcvLength);
                    Array.Clear(m_RecvDataBuffer, 0, m_RecvDataBuffer.Length);
                }
            }
            else//超出长度
            {
                byte[] temp = new byte[m_iRcvLength - recv];
                Buffer.BlockCopy(m_TotalBuffer, 0, temp, 0, temp.Length);
                Array.Clear(m_TotalBuffer, 0, m_TotalBuffer.Length);
                m_TotalBuffer = new byte[m_iRcvLength];
                Buffer.BlockCopy(temp, 0, m_TotalBuffer, 0, temp.Length);
                Buffer.BlockCopy(m_RecvDataBuffer, 0, m_TotalBuffer, temp.Length, recv);
                Array.Clear(m_RecvDataBuffer, 0, m_RecvDataBuffer.Length);
                temp = null;
            }

            while (true)
            {
                int iPacketLength = OnCheckPacket(ref m_TotalBuffer, m_iRcvLength, true); //返回包体的长度

                //包的正常长度
                if (iPacketLength >= 0)
                {
                    //包接受完毕,数据处理
                    NetMsg msg = MessageHelper.Instance.ParserPacket(m_TotalBuffer, iPacketLength, true);
                    EventDispatcher.Instance.InsertMsg(msg);
                    m_iRcvLength -= (iPacketLength + HEADER_LENGTH);

                    byte[] bufferData = new byte[m_iRcvLength];
                    Buffer.BlockCopy(m_TotalBuffer, iPacketLength + HEADER_LENGTH, bufferData, 0, bufferData.Length);
                    Array.Clear(m_TotalBuffer, 0, m_TotalBuffer.Length);
                    Buffer.BlockCopy(bufferData, 0, m_TotalBuffer, 0, bufferData.Length);

                    //长度为0,包体无内容
                    if (m_iRcvLength == 0)
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
        }