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 options to disable Nagle's algorithm (NoDelay) #327

Open
jaskie opened this issue Jan 25, 2017 · 6 comments
Open

Add options to disable Nagle's algorithm (NoDelay) #327

jaskie opened this issue Jan 25, 2017 · 6 comments

Comments

@jaskie
Copy link

jaskie commented Jan 25, 2017

Little enhancement: however sending realtime data over TCP is not best option, it would be nice to have such an option to have quicker responses in some cases. Am I right?

@NIA
Copy link

NIA commented Mar 14, 2017

Agree, such ability is highly appreciated for websocket application in real-time games. Any update on this?

@JuSiZeLa
Copy link

Agree. Maybe it would be better to have access to the TcpClient member so also other settings could be changed (eg. enable/disable KeepAlive)

@Xericore
Copy link

Hi, is there a reason #398 was never merged? Adding the option to have NoDelay would certainly be helpful in some use cases.

@dantezhu
Copy link

hi, is there any progress?

@AlexMog
Copy link

AlexMog commented Nov 6, 2020

If someone needs help with that, I found a way around it using Reflection:

var server = new WebSocketServer(address, port);
var listener = typeof(WebSocketServer).GetField("_listener").GetValue(_server) as TcpListener;
listener.Server.NoDelay = true;

@ercang
Copy link

ercang commented Feb 6, 2021

Thank you for providing the reflection workaround, that fixed my problem. On the client-side, a similar workaround should be done to disable the delay. I am using WebSocket-sharp both on the server and on the client. TCP client is accessible after the connection is opened.

WebSocketServer

using System.Reflection;

socketServer = new WebSocketServer(5555);
var listener = typeof(WebSocketServer).GetField("_listener", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(socketServer) as System.Net.Sockets.TcpListener;
listener.Server.NoDelay = true;

WebSocketClient

using System.Reflection;

ws = new WebSocket(uri);
ws.OnOpen += OnConnectionOpened;
...
private void OnConnectionOpened(object sender, System.EventArgs e)
{
    var tcpClient = typeof(WebSocket).GetField("_tcpClient", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(ws) as System.Net.Sockets.TcpClient;
    tcpClient.NoDelay = true;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants