示例#1
0
 public void OnUpdate()
 {
     while (true)
     {
         if (m_ReceiveCount < 5)
         {
             ++m_ReceiveCount;
             lock (m_ReceiveQueue)
             {
                 if (m_ReceiveQueue.Count > 0)
                 {
                     byte[] buffer          = m_ReceiveQueue.Dequeue();
                     byte[] protocodeBuffer = new byte[4];
                     byte[] protoContent    = new byte[buffer.Length - 5];
                     bool   isCompress      = false;
                     using (MemoryStreamExt ms = new MemoryStreamExt(buffer))
                     {
                         isCompress = ms.ReadBool();
                         ms.Read(protocodeBuffer, 0, protocodeBuffer.Length);
                         Array.Reverse(protocodeBuffer);
                         int protoCode = BitConverter.ToInt32(protocodeBuffer, 0);
                         LogSystem.Log("=============================================================收到消息" + protoCode);
                         ms.Read(protoContent, 0, protoContent.Length);
                         if (isCompress)
                         {
                             protoContent = GZipCompress.DeCompress(protoContent);
                         }
                         if (protoCode == OP_PLAYER_CLOSE.CODE)
                         {
                             LogSystem.LogSpecial("服务器返回关闭消息,网络连接断开");
                             Close(true);
                         }
                         else if (protoCode == OP_SYS_HEART.CODE)
                         {
                             lastHeart = OP_SYS_HEART.decode(protoContent);
                         }
                         else
                         {
                             //return;
                             NetDispatcher.Instance.Dispatch(protoCode, protoContent);
                         }
                     }
                 }
                 else
                 {
                     break;
                 }
             }
         }
         else
         {
             m_ReceiveCount = 0;
             break;
         }
     }
     m_SocketStateDic[m_CurrentState].OnUpdate();
 }