void SendReply(byte[] msgArray, int len)
    {
        string temp = TCPServer.CompileBytesIntoString(msgArray, len);

        Debug.Log(string.Format("Client sending: len: {1} '{0}'", temp, len));
        m_clientSocket.BeginSend(msgArray, 0, len, SocketFlags.None, EndSend, msgArray);
    }
예제 #2
0
    void SendMessage(byte[] msg)
    {
        string temp = TCPServer.CompileBytesIntoString(msg);

        Debug.Log(string.Format("Server sending: '{0}'", temp));
        m_testClientSocket.BeginSend(msg, 0, msg.Length, SocketFlags.None, EndSend, msg);
    }
    void EndSend(System.IAsyncResult iar)
    {
        m_clientSocket.EndSend(iar);
        byte[] msg  = (iar.AsyncState as byte[]);
        string temp = TCPServer.CompileBytesIntoString(msg, msg.Length);

        Debug.Log(string.Format("Client sent: '{0}'", temp));
        System.Array.Clear(msg, 0, msg.Length);
        msg = null;
    }
    void ProcessData(int numBytesRecv)
    {
        string temp = TCPServer.CompileBytesIntoString(m_readBuffer, numBytesRecv);

        Debug.Log(string.Format("Client recv: '{0}'", temp));
        byte[] replyMsg = new byte[m_readBuffer.Length];
        System.Buffer.BlockCopy(m_readBuffer, 0, replyMsg, 0, numBytesRecv);

        //Increment first byte and send it back
        replyMsg[0] = (byte)((int)replyMsg[0] + 1);

        SendReply(replyMsg, numBytesRecv);
    }
예제 #5
0
    void ProcessData(int numBytesRecv)
    {
        string temp = TCPServer.CompileBytesIntoString(m_readBuffer, numBytesRecv);

        Debug.Log(string.Format("Server recv: '{0}'", temp));
        byte firstByte = m_readBuffer[0];

        switch (firstByte)
        {
        case 1:
            Debug.LogError(string.Format("Server should not receive first byte of 1"));
            m_testClientState = TestMessageOrder.Error;
            break;

        case 2:
            m_testClientState = TestMessageOrder.ReceiveSecondMessageReply;
            break;

        case 3:
            Debug.LogError(string.Format("Server should not receive first byte of 3"));
            m_testClientState = TestMessageOrder.Error;
            break;

        case 4:
            m_testClientState = TestMessageOrder.ReceiveThirdMessageReply;
            break;

        case 5:
            Debug.LogError(string.Format("Server should not receive first byte of 5"));
            m_testClientState = TestMessageOrder.Error;
            break;

        default:
            Debug.LogError(string.Format("Server should not receive first byte of {0}", firstByte));
            m_testClientState = TestMessageOrder.Error;
            break;
        }
        SendTestData();
    }