Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add LocalEndPoint to SimpleTcpClientSettings and set NoDelay in InitializeClient of SimpleTcpClient #206

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading