// TODO: implement universal logging /// <summary> /// Ctor; Establishes a new connection to the remote party for sending and or receiving data /// </summary> /// <param name="logger">Logger instance that implements ISimpleNetworkingClientLogger for diagnostic logging</param> /// <param name="host">Hostname or ip address to connect to</param> /// <param name="port">Port to use</param> /// <param name="sendReadTimeout">Send/Read timeout</param> /// <param name="bufferSize">Size of the tcp buffer that determines the amount of bytes that is received/send per chunk</param> /// <param name="stxCharacters">Begin of transmission characters, Eg 0x02 for ASCII char STX. Set to null to disable to disable adding/removing stx characters.</param> /// <param name="etxCharacters">End of transmission characters, Eg 0x03 for ASCII char ETX. Set to null to disable end of transmission checking.</param> public TcpSendConnection(ISimpleNetworkingClientLogger logger, string host, int port, TimeSpan sendReadTimeout, int bufferSize, IList <byte> stxCharacters = null, IList <byte> etxCharacters = null) : base(logger, sendReadTimeout, bufferSize) { _host = host; _port = port; _stxCharacters = stxCharacters; _etxCharacters = etxCharacters; StartConnection(); }
/// <summary> /// Ctor; Sets defaults for the connection base class /// </summary> /// <param name="logger">Logger instance that implements ISimpleNetworkingClientLogger for diagnostic logging</param> /// <param name="sendReadTimeout">Send/Read timeout</param> /// <param name="bufferSize"> /// Size of the tcp buffer that determines the amount of bytes that is received/send per chunk to the operating system(OS) networking stack. /// This is not equal to the Maximum Transfer Unit, which controls the maximum number of bytes send out from the OS networking stack in one tcp frame /// </param> protected TcpConnectionBase(ISimpleNetworkingClientLogger logger, TimeSpan sendReadTimeout, int bufferSize) { _logger = logger; _sendReadTimeout = sendReadTimeout; _bufferSize = bufferSize; _sendReadTimeoutMicroseconds = (int)_sendReadTimeout.TotalMilliseconds * 1000; if (_sendReadTimeout == null || _sendReadTimeout <= TimeSpan.Zero) { throw new ArgumentException($"{nameof(sendReadTimeout)} must be set to a value higher than zero seconds"); } if (_bufferSize <= 0) { throw new ArgumentException($"{nameof(bufferSize)} must be larger than zero"); } _logger?.Verbose($"{nameof(TcpConnectionBase)} ctor has been initialized. {nameof(sendReadTimeout)}={sendReadTimeout}, Tcp buffer size={bufferSize}"); }
/// <summary> /// Ctor; Starts a new tcp listener /// </summary> /// <param name="logger">Logger instance that implements ISimpleNetworkingClientLogger for diagnostic logging</param> /// <param name="port">Port on which to listen for incoming connections</param> /// <param name="sendReadTimeout">Send/Read timeout</param> /// <param name="bufferSize">Size of the tcp buffer that determines the amount of bytes that is received/send per chunk</param> /// <param name="stxCharacters">Begin of transmission characters, Eg 0x02 for ASCII char STX. Set to null to disable to disable adding/removing stx characters.</param> /// <param name="etxCharacters">End of transmission characters, Eg 0x03 for ASCII char ETX. Set to null to disable end of transmission checking.</param> public TcpReadConnectionDeadlockSimulator(ISimpleNetworkingClientLogger logger, int port, TimeSpan sendReadTimeout, int bufferSize, IList <byte> stxCharacters = null, IList <byte> etxCharacters = null) : base(logger, sendReadTimeout, bufferSize) { _port = port; _stxCharacters = stxCharacters; _etxCharacters = etxCharacters; }