private ITcpClient CreateClient() { var tcpClient = _tcpClientFactory.Create(); tcpClient.SendBufferSize = SendBufferSize; tcpClient.ReceiveBufferSize = ReceiveBufferSize; return(tcpClient); }
public async Task Open(CancellationToken ct) { if (_client != null) { throw new InvalidOperationException(); } _client = _tcpClientFactory.Create(_address, false); var isConnected = false; try { _client.ReadWriteTimeout = ReadWriteTimeout; _client.Timeout = Timeout; // Connect await _client.Open(ct); isConnected = true; // Authenticate with proxy server await Authenticate(ct); // Open connection to destination address through proxy server await Connect(_destinationAddress, ct); // Do we need SSL? _networkStream = _client.GetStream(); if (_useSsl) { _networkStream = await _tcpClientFactory.CreateSslStream(_networkStream, _destinationAddress.Host); } } catch { if (isConnected) { _client.Close(); } _client = null; throw; } }