public void Connect()
{
m_Client = new TcpClient(m_ServerAddr, m_TcpPort);
m_Client.NoDelay = true;
// on Azure sockets will be closed after some minutes idle.
// which for some reason messes up this library causing it to lose data.
// turn on keepalive, to keep the sockets open.
// I don't really understand why this helps the problem, since the socket already has NoDelay set
// so data should be sent immediately. And indeed it does appear to be sent promptly when it works.
m_Client.Client.SetSocketOption( SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
// set timeouts to 10 seconds idle before keepalive, 1 second between repeats,
SetSocketKeepAliveValues(m_Client, 10 *1000, 1000);
m_Stream = m_Client.GetStream();
if (m_UseSsl)
{
m_SslStream = new SslStream(m_Stream, false, (sender, certificate, chain, sslPolicyErrors) =>
{
// HACK-HACK: Do not check the server name until our LogEntries forwarder is not ready.
if (sslPolicyErrors == SslPolicyErrors.None || sslPolicyErrors == SslPolicyErrors.RemoteCertificateNameMismatch)
{
return true;
}
return false;
}
);
m_SslStream.AuthenticateAsClient(m_ServerAddr);
}
}