public void Connect(EndPoint remoteEP)
{
if (CleanedUp)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
// Validate input parameters.
if (remoteEP == null)
{
throw new ArgumentNullException(nameof(remoteEP));
}
if (_isDisconnected)
{
throw new InvalidOperationException(SR.net_sockets_disconnectedConnect);
}
if (_isListening)
{
throw new InvalidOperationException(SR.net_sockets_mustnotlisten);
}
ValidateBlockingMode();
if (NetEventSource.IsEnabled)
{
if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"DST:{remoteEP}");
}
DnsEndPoint dnsEP = remoteEP as DnsEndPoint;
if (dnsEP != null)
{
if (dnsEP.AddressFamily != AddressFamily.Unspecified && !CanTryAddressFamily(dnsEP.AddressFamily))
{
throw new NotSupportedException(SR.net_invalidversion);
}
Connect(dnsEP.Host, dnsEP.Port);
return;
}
// This will check the permissions for connect
EndPoint endPointSnapshot = remoteEP;
Internals.SocketAddress socketAddress = CheckCacheRemote(ref endPointSnapshot, true);
if (!Blocking)
{
_nonBlockingConnectRightEndPoint = endPointSnapshot;
_nonBlockingConnectInProgress = true;
}
DoConnect(endPointSnapshot, socketAddress);
}