Пример #1
0
        private void DoReceiveInMain()
        {
            m_RecvBufQueue.Switch();

            while (!m_RecvBufQueue.Empty())
            {
                var recvBufferRaw = m_RecvBufQueue.Pop();
                int ret           = m_Kcp.Input(recvBufferRaw, recvBufferRaw.Length);

                //收到的不是一个正确的KCP包
                if (ret < 0)
                {
                    Debuger.LogError("收到不正确的KCP包!Ret:{0}", ret);
                    return;
                }

                m_NeedKcpUpdateFlag = true;

                for (int size = m_Kcp.PeekSize(); size > 0; size = m_Kcp.PeekSize())
                {
                    var recvBuffer = new byte[size];
                    if (m_Kcp.Recv(recvBuffer) > 0)
                    {
                        NetMessage msg = new NetMessage();
                        msg.Deserialize(recvBuffer, size);

                        m_listener.OnReceive(this, msg);
                    }
                }
            }
        }
Пример #2
0
        private void DoReceiveInMain()
        {
            recvBufQueue.Switch();

            while (!recvBufQueue.Empty())
            {
                var recvBufferRaw = recvBufQueue.Pop();
                int ret           = kcp.Input(recvBufferRaw, recvBufferRaw.Length);
                if (ret < 0)
                {
                    Debuger.LogError("收到不正确的KCP包!Ret:{0}", ret);
                    return;
                }
                needKcpUpdateFlag = true;

                for (int size = kcp.PeekSize(); size > 0; size = kcp.PeekSize())
                {
                    var recvBuffer = new byte[size];
                    if (kcp.Recv(recvBuffer) > 0)
                    {
                        listener.OnReceive(this, recvBuffer, size);
                    }
                }
            }
        }
Пример #3
0
 public void Tick(int currentMS)
 {
     var msg = base.Receive();
     while (msg != null)
     {
         m_listener.OnReceive(this, msg);
         msg = base.Receive();
     }
 }
Пример #4
0
 private void ReceiveDataHandle()
 {
     byte[] data = LengthEncoding.LengthDecode(ref readBuffer);
     if (data == null)
     {
         isReading = false;
         return;
     }
     listener.OnReceive(this, data, data.Length);
     ReceiveDataHandle();
 }