Beispiel #1
0
        public void Socket_StaticConnectAsync_Success(SocketImplementationType type)
        {
            Assert.True(Capability.IPv4Support() && Capability.IPv6Support());

            int port4, port6;
            SocketTestServer server4 = SocketTestServer.SocketTestServerFactory(type, IPAddress.Loopback, out port4);
            SocketTestServer server6 = SocketTestServer.SocketTestServerFactory(type, IPAddress.IPv6Loopback, out port6);

            SocketAsyncEventArgs args = new SocketAsyncEventArgs();

            args.RemoteEndPoint = new DnsEndPoint("localhost", port4);
            args.Completed     += OnConnectAsyncCompleted;

            ManualResetEvent complete = new ManualResetEvent(false);

            args.UserToken = complete;

            Assert.True(Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, args));

            Assert.True(complete.WaitOne(Configuration.PassingTestTimeout), "Timed out while waiting for connection");

            Assert.Equal(SocketError.Success, args.SocketError);
            Assert.Null(args.ConnectByNameError);
            Assert.NotNull(args.ConnectSocket);
            Assert.True(args.ConnectSocket.AddressFamily == AddressFamily.InterNetwork);
            Assert.True(args.ConnectSocket.Connected);

            args.ConnectSocket.Dispose();

            args.RemoteEndPoint = new DnsEndPoint("localhost", port6);
            complete.Reset();

            Assert.True(Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, args));

            Assert.True(complete.WaitOne(Configuration.PassingTestTimeout), "Timed out while waiting for connection");

            Assert.Equal(SocketError.Success, args.SocketError);
            Assert.Null(args.ConnectByNameError);
            Assert.NotNull(args.ConnectSocket);
            Assert.True(args.ConnectSocket.AddressFamily == AddressFamily.InterNetworkV6);
            Assert.True(args.ConnectSocket.Connected);

            args.ConnectSocket.Dispose();

            server4.Dispose();
            server6.Dispose();
        }
        public void ConnectEx_Success(SocketImplementationType type)
        {
            Assert.True(Capability.IPv4Support() && Capability.IPv6Support());

            int port;
            SocketTestServer server = SocketTestServer.SocketTestServerFactory(type, IPAddress.Loopback, out port);

            int port6;
            SocketTestServer server6 = SocketTestServer.SocketTestServerFactory(type, IPAddress.IPv6Loopback, out port6);

            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                SocketAsyncEventArgs args = new SocketAsyncEventArgs();
                args.RemoteEndPoint = new IPEndPoint(IPAddress.Loopback, port);
                args.Completed     += OnConnectAsyncCompleted;

                ManualResetEvent complete = new ManualResetEvent(false);
                args.UserToken = complete;

                Assert.True(sock.ConnectAsync(args));
                Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "IPv4: Timed out while waiting for connection");
                Assert.True(args.SocketError == SocketError.Success);

                sock.Dispose();

                sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
                args.RemoteEndPoint = new IPEndPoint(IPAddress.IPv6Loopback, port6);
                complete.Reset();

                Assert.True(sock.ConnectAsync(args));
                Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "IPv6: Timed out while waiting for connection");
                Assert.True(args.SocketError == SocketError.Success);
            }
            finally
            {
                sock.Dispose();

                server.Dispose();
                server6.Dispose();
            }
        }
Beispiel #3
0
        public void Success()
        {
            int port;
            SocketTestServer server  = SocketTestServer.SocketTestServerFactory(IPAddress.Loopback, out port);
            SocketTestServer server6 = SocketTestServer.SocketTestServerFactory(new IPEndPoint(IPAddress.IPv6Loopback, port));

            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            SocketAsyncEventArgs args = new SocketAsyncEventArgs();

            args.RemoteEndPoint = new IPEndPoint(IPAddress.Loopback, port);
            args.Completed     += OnConnectAsyncCompleted;

            ManualResetEvent complete = new ManualResetEvent(false);

            args.UserToken = complete;

            Assert.True(sock.ConnectAsync(args));

            Assert.True(complete.WaitOne(Configuration.PassingTestTimeout), "IPv4: Timed out while waiting for connection");

            Assert.True(args.SocketError == SocketError.Success);

            sock.Dispose();

            sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
            args.RemoteEndPoint = new IPEndPoint(IPAddress.IPv6Loopback, port);
            complete.Reset();

            Assert.True(sock.ConnectAsync(args));

            Assert.True(complete.WaitOne(Configuration.PassingTestTimeout), "IPv6: Timed out while waiting for connection");

            Assert.True(args.SocketError == SocketError.Success);

            sock.Dispose();

            server.Dispose();
            server6.Dispose();
        }