Skip to content

Commit

Permalink
Merge pull request #206 from huangjia2107/master
Browse files Browse the repository at this point in the history
add LocalEndPoint to SimpleTcpClientSettings and set NoDelay in InitializeClient of SimpleTcpClient
  • Loading branch information
jchristn authored Jan 16, 2024
2 parents 7b3bc15 + 3103a9f commit 73879c0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/SuperSimpleTcp/SimpleTcp.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/SuperSimpleTcp/SimpleTcpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions src/SuperSimpleTcp/SimpleTcpClientSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Net;
using System.Net.Security;

namespace SuperSimpleTcp
Expand All @@ -10,6 +11,21 @@ public class SimpleTcpClientSettings
{
#region Public-Members

/// <summary>
/// The System.Net.IPEndPoint to which you bind the TCP System.Net.Sockets.Socket
/// </summary>
public IPEndPoint LocalEndpoint
{
get
{
return _LocaleEndpoint;
}
set
{
_LocaleEndpoint = value;
}
}

/// <summary>
/// Nagle's algorithm.
/// Gets or sets a value that disables a delay when send or receive buffers are not full.
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 73879c0

Please sign in to comment.