diff --git a/src/SuperSimpleTcp/SimpleTcp.xml b/src/SuperSimpleTcp/SimpleTcp.xml index 7349607..3e670a0 100644 --- a/src/SuperSimpleTcp/SimpleTcp.xml +++ b/src/SuperSimpleTcp/SimpleTcp.xml @@ -353,6 +353,11 @@ SimpleTcp client settings. + + + The System.Net.IPEndPoint to which you bind the TCP System.Net.Sockets.Socket + + Nagle's algorithm. diff --git a/src/SuperSimpleTcp/SimpleTcpClient.cs b/src/SuperSimpleTcp/SimpleTcpClient.cs index 1137d62..8d549b2 100644 --- a/src/SuperSimpleTcp/SimpleTcpClient.cs +++ b/src/SuperSimpleTcp/SimpleTcpClient.cs @@ -572,7 +572,7 @@ public void ConnectWithRetries(int? timeoutMs = null) Logger?.Invoke(msg); _client.Dispose(); - _client = new TcpClient(); + _client = _settings.LocalEndpoint == null ? new TcpClient() : new TcpClient(_settings.LocalEndpoint); _client.NoDelay = _settings.NoDelay; _client.ConnectAsync(_serverIp, _serverPort).Wait(1000, connectToken); @@ -846,7 +846,10 @@ private void InitializeClient(bool ssl, string pfxCertFilename, string pfxPasswo _ssl = ssl; _pfxCertFilename = pfxCertFilename; _pfxPassword = pfxPassword; - _client = new TcpClient(); + + _client = _settings.LocalEndpoint == null ? new TcpClient() : new TcpClient(_settings.LocalEndpoint); + _client.NoDelay = _settings.NoDelay; + _sslStream = null; _sslCert = null; _sslCertCollection = null; diff --git a/src/SuperSimpleTcp/SimpleTcpClientSettings.cs b/src/SuperSimpleTcp/SimpleTcpClientSettings.cs index f345471..6bc8c0a 100644 --- a/src/SuperSimpleTcp/SimpleTcpClientSettings.cs +++ b/src/SuperSimpleTcp/SimpleTcpClientSettings.cs @@ -1,4 +1,5 @@ using System; +using System.Net; using System.Net.Security; namespace SuperSimpleTcp @@ -10,6 +11,21 @@ public class SimpleTcpClientSettings { #region Public-Members + /// + /// The System.Net.IPEndPoint to which you bind the TCP System.Net.Sockets.Socket + /// + public IPEndPoint LocalEndpoint + { + get + { + return _LocaleEndpoint; + } + set + { + _LocaleEndpoint = value; + } + } + /// /// Nagle's algorithm. /// Gets or sets a value that disables a delay when send or receive buffers are not full. @@ -157,6 +173,7 @@ public int ConnectionLostEvaluationIntervalMs #region Private-Members + private IPEndPoint _LocaleEndpoint = null; private bool _noDelay = true; private int _streamBufferSize = 65536; private int _connectTimeoutMs = 5000;