Ejemplo n.º 1
0
        public void TcpClientConnectingToWrongIpAndThrowingOwnException()
        {
            var t = new Task(StartListeningV4);
            t.Start();
            try
            {
                var client = new TcpClient(
                    new IPEndPoint(new IPAddress(new byte[] {126, 0, 0, 1}), Port));

                const string message = "to jest wiadomosc do przekazania";

                var data = Encoding.UTF8.GetBytes(message);

                var received = client.SendData(data);
            }
            catch (TimeoutException e)
            {
                EndConnection();
                throw e;
            }
            catch (Exception)
            {
                EndConnection();
                throw;
            }

            //throw new Exception();
        }
Ejemplo n.º 2
0
        public void TcpClientConnectingWithSpecifiedSocketAndReceivingAnswerIpV4()
        {
            var client = new TcpClient(new IPEndPoint(_ipAddressv4, Port));

            const string message = "to jest wiadomosc do przekazania";

            var data = Encoding.UTF8.GetBytes(message);

            var t = new Task(ListenAndResendV4);
            t.Start();
            var received = client.SendData(data);

            Assert.AreEqual(data.Length, received.Length);
            for (var i = 0; i < data.Length; ++i)
            {
                Assert.AreEqual(data[i], received[i]);
                i++;
            }
            //check whether wait or dispose
            EndConnection();
            t.Wait();
        }