コード例 #1
0
ファイル: NetworkInterface.cs プロジェクト: zuig/uLui
    public void process()
    {
        int hasRecieved = 0;

        while (hasRecieved < MAX_PACKETS_PER_FRAME)
        {
            if (m_tcpWorker == null)
            {
                return;
            }

            byte[] data = m_tcpWorker.Recv();
            if (data == null || data.Length == 0)
            {
                // check network state
                break;
            }
            else
            {
                if (NetworkInterface.OnDataReceive != null)
                {
                    bool isEncrypt = BitConverter.ToBoolean(data, 0);
                    int  msgid     = BitConverter.ToInt32(data, 1);
                    int  nLength   = BitConverter.ToInt32(data, 1 + 4);

                    byte[] packet = new byte[nLength];
                    Buffer.BlockCopy(data, 4 + 4 + 1, packet, 0, nLength);

                    NetworkInterface.OnDataReceive(msgid, new SLua.ByteArray(packet), isEncrypt);
                }
                hasRecieved++;
            }
        }
    }
コード例 #2
0
    public void Process()
    {
        int hasReceived = 0;

        while (hasReceived < MAX_PACKETS_PER_FRAME)
        {
            if (m_tcpWorker == null)
            {
                return;
            }

            byte[] data = m_tcpWorker.Recv();
            if (data == null || data.Length == 0)
            {
                break;
            }
            else
            {
                Execute(data);
                hasReceived++;
            }
        }
    }