예제 #1
0
        public virtual async Task ConnectAsync(string host, int port)
        {
            AssertSocket();
            var adds = await Dns.GetHostAddressesAsync(host).ConfigureAwait(false);

            var ep = TcpClientAdapterHelper.GetMatchingHost(adds, sock.AddressFamily);

            if (ep == default(IPAddress))
            {
                throw new ArgumentException("No ip address could be resolved for " + host);
            }

            await sock.ConnectAsync(ep, port).ConfigureAwait(false);
        }
예제 #2
0
        public virtual async Task ConnectAsync(string host, int port)
        {
            AssertSocket();
            IPAddress[] adds = await Dns.GetHostAddressesAsync(host).ConfigureAwait(false);

            IPAddress ep = TcpClientAdapterHelper.GetMatchingHost(adds, _sock.AddressFamily);

            if (ep == default(IPAddress))
            {
                throw new ArgumentException("No ip address could be resolved for " + host);
            }

#if CORECLR
            await _sock.ConnectAsync(ep, port).ConfigureAwait(false);
#else
            await Task.Run(() => _sock.Connect(ep, port));
#endif
        }
예제 #3
0
        public virtual async Task ConnectAsync(string host, int port)
#endif
        {
            AssertSocket();
#if NET35
            var adds = Dns.GetHostAddresses(host);
#else
            var adds = await Dns.GetHostAddressesAsync(host).ConfigureAwait(false);
#endif
            var ep = TcpClientAdapterHelper.GetMatchingHost(adds, sock.AddressFamily);
            if (ep == default(IPAddress))
            {
                throw new ArgumentException("No ip address could be resolved for " + host);
            }
            #if CORECLR
            await sock.ConnectAsync(ep, port).ConfigureAwait(false);
            #else
            sock.Connect(ep, port);
            #endif
#if NET35
            return(TaskEx.FromResult(0));
#endif
        }
예제 #4
0
        public virtual async Task ConnectAsync(string host, int port)
        {
            AssertSocket();
            var adds = await Dns.GetHostAddressesAsync(host).ConfigureAwait(false);

            var ep = TcpClientAdapterHelper.GetMatchingHost(adds, sock.AddressFamily);

            if (ep == null)
            {
                if (adds.Length != 0)
                {
                    throw new NotSupportedException("Resolved ip address doesn't support " + sock.AddressFamily);
                }

                throw new ArgumentException("No ip address could be resolved for " + host);
            }

            #if CORECLR
            await sock.ConnectAsync(ep, port).ConfigureAwait(false);
            #else
            sock.Connect(ep, port);
            #endif
        }