Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 4
0
        public IEnumerator Setup() => UniTask.ToCoroutine(async() =>
        {
            // each test goes in a different port
            // that way the transports can take some time to cleanup
            // without interfering with each other.
            port++;

            var transportGo = new GameObject("kcpTransport", typeof(KcpTransport));

            transport = transportGo.GetComponent <KcpTransport>();

            transport.Port = port;
            // speed this up
            transport.HashCashBits = 3;

            transport.Connected.AddListener(connection => serverConnection = (KcpConnection)connection);

            listenTask = transport.ListenAsync();

            var uriBuilder = new UriBuilder
            {
                Host   = "localhost",
                Scheme = "kcp",
                Port   = port
            };

            testUri = uriBuilder.Uri;

            clientConnection = (KcpConnection)await transport.ConnectAsync(uriBuilder.Uri);

            await UniTask.WaitUntil(() => serverConnection != null);

            // for our tests,  lower the timeout to just 0.1s
            // so that the tests run quickly.
            serverConnection.Timeout = 500;
            clientConnection.Timeout = 500;

            data = new byte[Random.Range(10, 255)];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = (byte)Random.Range(1, 255);
            }
        });
Ejemplo n.º 5
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));
            }
        }