public void Connect(string host, int port)
{
if (NetEventSource.IsEnabled) NetEventSource.Enter(this, host);
if (CleanedUp)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
if (host == null)
{
throw new ArgumentNullException(nameof(host));
}
if (!TcpValidationHelpers.ValidatePortNumber(port))
{
throw new ArgumentOutOfRangeException(nameof(port));
}
if (_addressFamily != AddressFamily.InterNetwork && _addressFamily != AddressFamily.InterNetworkV6)
{
throw new NotSupportedException(SR.net_invalidversion);
}
IPAddress parsedAddress;
if (IPAddress.TryParse(host, out parsedAddress))
{
Connect(parsedAddress, port);
}
else
{
IPAddress[] addresses = Dns.GetHostAddressesAsync(host).GetAwaiter().GetResult();
Connect(addresses, port);
}
if (NetEventSource.IsEnabled) NetEventSource.Exit(this);
}