コード例 #1
0
        public void Socket_StaticConnectAsync_IPv6MappedIPv4_Success()
        {
            using SocketTestServer server = SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, IPAddress.Loopback, out int port);

            SocketAsyncEventArgs args = new SocketAsyncEventArgs();

            args.RemoteEndPoint = new DnsEndPoint("[::FFFF:127.0.0.1]", port);
            args.Completed     += OnConnectAsyncCompleted;

            ManualResetEvent complete = new ManualResetEvent(false);

            args.UserToken = complete;

            if (Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, args))
            {
                Assert.True(complete.WaitOne(TestSettings.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.Connected);
            args.ConnectSocket.Dispose();
        }
コード例 #2
0
ファイル: DisconnectAsync.cs プロジェクト: pgavlin/corefx
        public void Success()
        {
            AutoResetEvent completed = new AutoResetEvent(false);

            if (Socket.OSSupportsIPv4)
            {
                int port1, port2;
                using (SocketTestServer.SocketTestServerFactory(IPAddress.Loopback, out port1))
                    using (SocketTestServer.SocketTestServerFactory(IPAddress.Loopback, out port2))
                    {
                        SocketAsyncEventArgs args = new SocketAsyncEventArgs();
                        args.Completed            += OnCompleted;
                        args.UserToken             = completed;
                        args.RemoteEndPoint        = new IPEndPoint(IPAddress.Loopback, port1);
                        args.DisconnectReuseSocket = true;

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

                        Assert.True(client.ConnectAsync(args));
                        Assert.True(completed.WaitOne(Configuration.PassingTestTimeout), "Timed out while waiting for connection");
                        Assert.Equal <SocketError>(SocketError.Success, args.SocketError);

                        Assert.True(client.DisconnectAsync(args));
                        Assert.True(completed.WaitOne(Configuration.PassingTestTimeout), "Timed out while waiting for connection");
                        Assert.Equal <SocketError>(SocketError.Success, args.SocketError);

                        args.RemoteEndPoint = new IPEndPoint(IPAddress.Loopback, port2);

                        Assert.True(client.ConnectAsync(args));
                        Assert.True(completed.WaitOne(Configuration.PassingTestTimeout), "Timed out while waiting for connection");
                        Assert.Equal <SocketError>(SocketError.Success, args.SocketError);

                        client.Dispose();
                    }
            }
        }