Example #1
0
        public void ServerToClientTooLargeReliableMessage()
        {
            server.Start(Port);
            ConnectClientBlocking();
            int connectionId = ServerFirstConnectionId();

            byte[] message = new byte[KcpConnection.ReliableMaxMessageSize(ReceiveWindowSize) + 1];
#if UNITY_2018_3_OR_NEWER
            UnityEngine.TestTools.LogAssert.Expect(UnityEngine.LogType.Error, $"Failed to send reliable message of size {message.Length} because it's larger than ReliableMaxMessageSize={KcpConnection.ReliableMaxMessageSize(ReceiveWindowSize)}");
#endif
            SendServerToClientBlocking(connectionId, new ArraySegment <byte>(message), KcpChannel.Reliable);
            Assert.That(clientReceived.Count, Is.EqualTo(0));
        }
Example #2
0
        public void ClientToServerReliableMaxSizedMessage()
        {
            server.Start(Port);
            ConnectClientBlocking();

            byte[] message = new byte[KcpConnection.ReliableMaxMessageSize(ReceiveWindowSize)];
            for (int i = 0; i < message.Length; ++i)
            {
                message[i] = (byte)(i & 0xFF);
            }
            Log.Info($"Sending {message.Length} bytes = {message.Length / 1024} KB message");
            SendClientToServerBlocking(new ArraySegment <byte>(message), KcpChannel.Reliable);
            Assert.That(serverReceived.Count, Is.EqualTo(1));
            Assert.That(serverReceived[0].data.SequenceEqual(message), Is.True);
            Assert.That(serverReceived[0].channel, Is.EqualTo(KcpChannel.Reliable));
        }
Example #3
0
        public void ServerToClientReliableMaxSizedMessage()
        {
            server.Start(Port);
            ConnectClientBlocking();
            int connectionId = ServerFirstConnectionId();

            byte[] message = new byte[KcpConnection.ReliableMaxMessageSize(ReceiveWindowSize)];
            for (int i = 0; i < message.Length; ++i)
            {
                message[i] = (byte)(i & 0xFF);
            }

            SendServerToClientBlocking(connectionId, new ArraySegment <byte>(message), KcpChannel.Reliable);
            Assert.That(clientReceived.Count, Is.EqualTo(1));
            Assert.That(clientReceived[0].data.SequenceEqual(message), Is.True);
            Assert.That(clientReceived[0].channel, Is.EqualTo(KcpChannel.Reliable));
        }
Example #4
0
        public void ClientToServerMultipleReliableMaxSizedMessagesAtOnce()
        {
            server.Start(Port);
            ConnectClientBlocking();

            // prepare 10 different MTU sized messages.
            // each of them with unique content so we can guarantee arrival.
            List <byte[]> messages = new List <byte[]>();

            for (int i = 0; i < 10; ++i)
            {
                // create message, fill with unique data (j+i & 0xff)
                byte[] message = new byte[KcpConnection.ReliableMaxMessageSize(ReceiveWindowSize)];
                for (int j = 0; j < message.Length; ++j)
                {
                    message[j] = (byte)((j + i) & 0xFF);
                }
                messages.Add(message);
            }

            // send each one without updating server or client yet
            foreach (byte[] message in messages)
            {
                client.Send(new ArraySegment <byte>(message), KcpChannel.Reliable);
            }

            // each max sized message needs a lot of updates for all the fragments.
            // for multiple we need to update a lot more than usual.
            for (int i = 0; i < 10; ++i)
            {
                UpdateSeveralTimes();
            }

            // all received?
            Assert.That(serverReceived.Count, Is.EqualTo(messages.Count));
            for (int i = 0; i < messages.Count; ++i)
            {
                Assert.That(serverReceived[i].data.SequenceEqual(messages[i]), Is.True);
                Assert.That(serverReceived[i].channel, Is.EqualTo(KcpChannel.Reliable));
            }
        }