Example #1
0
        public void SimpleKcpTest()
        {
            lock (syncRoot)
            {
                connector = new KcpConnector(7758, "127.0.0.1", 7777);

                exitFlag = false;
                var thread = new Thread(Tick);
                thread.Start();

                var data   = new byte[0];
                var server = new KcpTestsServer(7758, (d) =>
                {
                    data = d;
                });

                var reData = new byte[0];
                connector.On(SocketEvents.Message, (d) =>
                {
                    reData = d as byte[];
                });

                var wait = connector.Connect();

                if (!Util.Wait(wait, 3000))
                {
                    exitFlag = true;
                    server.Dispose();
                    connector.Dispose();
                    Assert.Fail("wait faild");
                }

                wait = connector.Send(System.Text.Encoding.Default.GetBytes("hello world"));

                if (!Util.Wait(wait, 3000) ||
                    !Util.Wait(ref data, 3000) ||
                    !Util.Wait(ref reData, 3000))
                {
                    exitFlag = true;
                    server.Dispose();
                    connector.Dispose();
                    Assert.Fail("wait faild");
                }

                exitFlag = true;
                server.Dispose();
                connector.Disconnect();

                Console.WriteLine(System.Text.Encoding.Default.GetString(data));
                Console.WriteLine(System.Text.Encoding.Default.GetString(reData));
                Assert.AreEqual("hello world", System.Text.Encoding.Default.GetString(data));
                Assert.AreEqual("hello world", System.Text.Encoding.Default.GetString(reData));
            }
        }
Example #2
0
        public void TestDoubleConnect()
        {
            var connector = new KcpConnector(100, "127.0.0.1", 7777);
            var awaits    = connector.Connect();

            if (!Util.Wait(awaits, 3000))
            {
                Assert.Fail("wait faild");
            }

            var isThrow = false;

            try
            {
                connector.Connect();
            }
            catch (RuntimeException)
            {
                isThrow = true;
            }
            Assert.AreEqual(true, isThrow);
        }
Example #3
0
        public void TestDnsException()
        {
            var       connector = new KcpConnector(123, "http://123.0.0.1", 7777);
            Exception e         = null;

            connector.On(SocketEvents.Error, (ex) =>
            {
                e = ex as Exception;
            });

            var wait = connector.Connect();

            if (!Util.Wait(wait, 10000))
            {
                connector.Dispose();
                Assert.Fail("wait faild");
            }

            Assert.AreEqual(typeof(SocketException), (wait.Result as Exception).GetType());
        }