コード例 #1
0
        public void TestEvent()
        {
            bool isOnConnecting   = false;
            bool isOnConnected    = false;
            bool isOnDisconnected = false;
            bool isOnSend         = false;
            bool isOnReceive      = false;

            TcpSocket tcp = new TcpSocket();

            tcp.OnConnecting    += () => { isOnConnecting = true; };
            tcp.OnConnected     += () => { isOnConnected = true; };
            tcp.OnDisconnected  += () => { isOnDisconnected = true; };
            tcp.OnSocketSend    += (x) => { isOnSend = true; };
            tcp.OnSocketReceive += (x) => { isOnReceive = true; };

            tcp.Connect(Common.GetIpEndPoint());
            Assert.IsTrue(isOnConnecting);

            Common.WaitTrue(ref isOnConnected);
            Assert.IsTrue(isOnConnected);

            tcp.Send(new byte[10]);
            Common.WaitTrue(ref isOnSend);
            Assert.IsTrue(isOnSend);

            Common.WaitTrue(ref isOnReceive);
            Assert.IsTrue(isOnReceive);

            tcp.DisConnect();
            Assert.IsTrue(isOnDisconnected);
        }
コード例 #2
0
        public void TestConnect()
        {
            TcpSocket tcp = new TcpSocket();

            tcp.Connect(Common.GetIpEndPoint());

            //Test connected
            Common.WaitConnected(tcp);
            Assert.IsTrue(tcp.IsConnected);

            //Test disconnect
            tcp.DisConnect();
            Assert.IsFalse(tcp.IsConnected);

            tcp.Dispose();
        }
コード例 #3
0
        public void TestSendReceive()
        {
            var tcp = new TcpSocket();

            tcp.Connect(Common.GetIpEndPoint());
            Common.WaitConnected(tcp);
            int length = 0;

            tcp.OnSocketReceive += (x) =>
            {
                length = x.Length;
            };
            tcp.Send(new byte[10]);
            Common.WaitValue(ref length, 10);
            tcp.DisConnect();
            Assert.AreEqual(length, 10);
        }
コード例 #4
0
        public void TestLargeMessage()
        {
            var tcp = new TcpSocket();

            tcp.Connect(Common.GetIpEndPoint());
            Common.WaitConnected(tcp);
            int length = 0;

            tcp.OnSocketReceive += (x) =>
            {
                length += x.Length;
            };
            tcp.Send(new byte[1 << 10]);
            Common.WaitValue(ref length, 1 << 10, 10000);
            tcp.DisConnect();
            Console.WriteLine(length);
            Assert.AreEqual(length, 1 << 10);
        }
コード例 #5
0
        public void TestEvent()
        {
            var  tcp          = new TcpSocket();
            bool isConnecting = false;

            tcp.OnConnecting += () => { isConnecting = true; };
            bool isConnected = false;

            tcp.OnConnected += () => { isConnected = true; };
            bool isDisconnected = false;

            tcp.OnDisconnected += () => { isDisconnected = true; };
            tcp.Connect(Common.GetIpEndPoint());
            Common.WaitConnect(tcp);
            tcp.DisConnect();
            Assert.IsTrue(isConnecting);
            Assert.IsTrue(isConnected);
            Assert.IsTrue(isDisconnected);
        }