Example #1
0
    public CSMsgS Recv()
    {
        CSMsgS msg = recvQueue.Dequeue();

        if (null != msg)
        {
            recvTime   = Time.time;
            retryCount = 0;
            isAlive    = true;
        }

        return(msg);
    }
Example #2
0
    void RecvThread()
    {
        IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, port);

        while (!terminate)
        {
            try
            {
                byte[] buffer = null;
                if (udpClient.Available > 0)
                {
                    buffer = udpClient.Receive(ref anyIP);
                }

                int usedSize = 0;
                if (null != buffer)
                {
                    CSMsgS             msg   = new CSMsgS();
                    TdrError.ErrorType error = msg.unpack(ref buffer, ref usedSize);
                    if (TdrError.ErrorType.TDR_NO_ERROR == error)
                    {
                        if (!recvQueue.Enqueue(msg))
                        {
                            recvQueue.Clear();
                            recvQueue.Enqueue(msg);
                        }
                    }
                    else
                    {
                        Debug.LogError("[NetworkUdp.RecvThread] unpack message failed.");
                    }
                }
            }
            catch (System.Exception e)
            {
                Debug.LogError("[NetworkUdp.RecvThread] recv exception: " + e.Message);
            }

            Thread.Sleep(1);
        }
    }
Example #3
0
    void RecvThread()
    {
        IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, port);

        while (!terminate)
        {
            try
            {
                byte[] buffer = null;
                if (udpClient.Available > 0)
                {
                    buffer = udpClient.Receive(ref anyIP);
                }

                int usedSize = 0;
                if (null != buffer)
                {
                    CSMsgS msg = new CSMsgS();
                    TdrError.ErrorType error = msg.unpack(ref buffer, ref usedSize);
                    if (TdrError.ErrorType.TDR_NO_ERROR == error)
                    {
                        if (!recvQueue.Enqueue(msg))
                        {
                            recvQueue.Clear();
                            recvQueue.Enqueue(msg);
                        }
                    }
                    else
                    {
                        Debug.LogError("[NetworkUdp.RecvThread] unpack message failed.");
                    }
                }
            }
            catch(System.Exception e)
            {
                Debug.LogError("[NetworkUdp.RecvThread] recv exception: " + e.Message);
            }

            Thread.Sleep(1);
        }
    }