public TcpClient(string hostname, int port)
{
if (NetEventSource.IsEnabled) NetEventSource.Enter(this, hostname);
if (hostname == null)
{
throw new ArgumentNullException(nameof(hostname));
}
if (!TcpValidationHelpers.ValidatePortNumber(port))
{
throw new ArgumentOutOfRangeException(nameof(port));
}
// IPv6: Delay creating the client socket until we have
// performed DNS resolution and know which address
// families we can use.
try
{
Connect(hostname, port);
}
catch
{
if (_clientSocket != null)
{
_clientSocket.Close();
}
throw;
}
if (NetEventSource.IsEnabled) NetEventSource.Exit(this);
}