コード例 #1
0
    public void AppendReceivedMessage(NetSocket socket, byte[] buffer, int size)
    {
        outTime     = 0;
        isConnected = true;

        NetHeader nh = NetBase.ByteArrayToNetHeader(buffer);

        //	we are waiting for received confirmation from the other side
        if ((nh.option & NetBase.NET_OPTN_CONFIRMED) > 0)
        {
            if (nh.number == confirmNumber && nh.checksum == confirmChecksum)
            {
                Debug.Log("Info: Message number has been confirmed from other side!");

                confirmNumber = 0;  // confirmed
                retryTime     = 0;

                // remove the message from the sending list
                m_sendingPacks.RemoveAt(0);
            }
            else
            {
                // do nothing !!
            }
        }
        else
        {
            //	replay to sender that safe message has been received
            if ((nh.option & NetBase.NET_OPTN_SAFESEND) > 0)
            {
                NetPacket tmp = new NetPacket();
                tmp.header        = nh;
                tmp.header.option = NetBase.NET_OPTN_CONFIRMED;
                socket.Send(tmp, dest);
            }

            //	create message container and append it to the list
            if (nh.number != recvNumber)
            {
                recvNumber = nh.number;

                NetPacket np = new NetPacket();
                np.header = nh;
                np.data   = new byte[size - NetBase.NET_HEADER_SIZE];

                Buffer.BlockCopy(buffer, NetBase.NET_HEADER_SIZE, np.data, 0, np.data.Length);

                //	add it to the received list
                m_receivedPacks.Add(np);

                //sx_print( L"message received header [NO: %d OP: %d CH: %d]\n", np.header.number, np.header.option, np.header.checksum );
            }
        }
    }
コード例 #2
0
ファイル: Connection.cs プロジェクト: seganx/old-engine
    public void AppendReceivedMessage(byte[] buffer, int size)
    {
        outTime     = 0;
        isConnected = true;

        byte[] headerBuffer = new byte[net.NET_HEADER_SIZE];

        Buffer.BlockCopy(buffer, 0, headerBuffer, 0, net.NET_HEADER_SIZE);

        NetHeader nh = net.ByteArrayToNetHeader(buffer);

        //	we are waiting for received confirmation from the other side
        if ((nh.option & net.NET_OPTN_CONFIRMED) > 0)
        {
            if (nh.number == confirmNumber && nh.checksum == confirmChecksum)
            {
                //sx_print(L"Info: Message number %d has been confirmed from other side!\n", confirmNumber);

                confirmNumber = 0;  // confirmed
                retryTime     = 0;

                // remove the message from the sending list
                m_sendingPacks.RemoveAt(0);
            }
            else
            {
                // do nothing !!
            }
        }
        else
        {
            //	replay to sender that safe message has been received
            if ((nh.option & net.NET_OPTN_SAFESEND) > 0)
            {
                NetPackage tmp = new NetPackage(net.NET_HEADER_SIZE, net.NET_BUFF_SIZE);
                tmp.header        = nh;
                tmp.header.option = net.NET_OPTN_CONFIRMED;
                byte[] tmpBuf = net.NetHeaderToByteArray(tmp.header);
                Buffer.BlockCopy(tmpBuf, 0, tmp.data, 0, net.NET_HEADER_SIZE);
                net.socket.Send(dest, tmp.data, tmp.size);
            }

            //	create message container and append it to the list
            if (nh.number != recvNumber)
            {
                recvNumber = nh.number;

                NetPackage np = new NetPackage(net.NET_HEADER_SIZE, net.NET_BUFF_SIZE);
                np.size = size;

                np.header = nh;

                Buffer.BlockCopy(buffer, 0, np.data, 0, size);

                //	add it to the received list
                m_receivedPacks.Add(np);

                //sx_print( L"message received header [NO: %d OP: %d CH: %d]\n", np.header.number, np.header.option, np.header.checksum );
            }
        }
    }