public void Connect(string hostname, int port)
{
if (NetEventSource.IsEnabled) NetEventSource.Enter(this, hostname);
if (_cleanedUp)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
if (hostname == null)
{
throw new ArgumentNullException(nameof(hostname));
}
if (!TcpValidationHelpers.ValidatePortNumber(port))
{
throw new ArgumentOutOfRangeException(nameof(port));
}
// Check for already connected and throw here. This check
// is not required in the other connect methods as they
// will throw from WinSock. Here, the situation is more
// complex since we have to resolve a hostname so it's
// easier to simply block the request up front.
if (_active)
{
throw new SocketException((int)SocketError.IsConnected);
}
ConnectCore(hostname, port);
if (NetEventSource.IsEnabled) NetEventSource.Exit(this);
}