Пример #1
0
        public void TestOnJoin()
        {
            NetworkClient testClient = new NetworkClient(matchID, username, SERVER_IP);
            testClient.Start();

            // Test this function
            testClient.SendInstruction(WDServer.Instruction.Type.JOIN, username, matchID);

            // Get response
            WDServer.Instruction receivedInstruction = WaitForResponse(testClient);

            // Expect to receive the JOINED command as a response
            Assert.AreEqual(receivedInstruction.Command, WDServer.Instruction.Type.JOINED);
        }
Пример #2
0
        private static WDServer.Instruction WaitForResponse(NetworkClient testClient)
        {
            byte[] receivedData = new byte[512];
            IPEndPoint receiverEndPoint = new IPEndPoint(IPAddress.Any, 0);

            // Block and wait
            receivedData = testClient.socket.Receive(ref receiverEndPoint);

            // Data received, remove trailing nulls
            int i = receivedData.Length - 1;
            while (receivedData[i] == 0)
                --i;
            byte[] data = new byte[i + 1];
            Array.Copy(receivedData, data, i + 1);

            // Deserialize recieved instruction
            WDServer.Instruction receivedInstruction = Serializer.DeSerialize(data);
            return receivedInstruction;
        }