/// <summary>
/// Initializes a client instance of <see cref="DesktopNetworkStream"/>.
/// </summary>
/// <param name="host">Network host.</param>
/// <param name="port">Network port.</param>
/// <param name="useTls">Use TLS layer?</param>
/// <param name="noDelay">No delay?</param>
/// <param name="ignoreSslPolicyErrors">Ignore SSL policy errors?</param>
internal DesktopNetworkStream(string host, int port, bool useTls, bool noDelay, bool ignoreSslPolicyErrors)
{
this.Host = host;
this.Port = port;
#if NETSTANDARD
this.tcpClient = new TcpClient { NoDelay = noDelay };
this.tcpClient.ConnectAsync(host, port).Wait();
#else
this.tcpClient = new TcpClient(host, port) { NoDelay = noDelay };
#endif
Stream stream = this.tcpClient.GetStream();
if (useTls)
{
var ssl = new SslStream(
stream,
false,
(sender, certificate, chain, errors) => errors == SslPolicyErrors.None || ignoreSslPolicyErrors);
#if NETSTANDARD
ssl.AuthenticateAsClientAsync(host).Wait();
#else
ssl.AuthenticateAsClient(host);
#endif
stream = ssl;
}
this.networkStream = stream;
}