Example #1
0
        /// <summary>
        /// Creates an underlying TCP connection
        /// </summary>
        /// <returns></returns>
        private Task ConnectAsync()
        {
            // ReSharper disable once UseObjectOrCollectionInitializer
            //create TCP connection
            _client = new TcpClient();

            //set buffer sizes
            _client.SendBufferSize = _config.SocketSendBufferSize;
            _client.ReceiveBufferSize = _config.SocketReceiveBufferSize;

            //set keepAlive if requested
            if (_config.SocketKeepAlive > 0) _client.SetKeepAlive((ulong)_config.SocketKeepAlive);

            //set Linger State
            var lingerState = _config.SocketSoLinger >= 0
                ? new LingerOption(true, _config.SocketSoLinger)
                : new LingerOption(false, 0);
            _client.LingerState = lingerState;

            //connect within requested timeout
            return _client.ConnectAsync(_node.Address, _config.Port, _config.SocketConnectTimeout);
        }