NetCoreServer
NetCoreServer copied to clipboard
TcpServer Receive Bottleneck
I wrote a simple TCP server/client application, where in rare situations the TcpClient sends short messages (SendAsync) to TcpServer without any delay (in a loop). The problem is: the client needs the replys from TcpServer so it can continue and go further... but at the TcpServer side, the replys to client are not pumped (approximately) immediately and are "collected". These collected replays are then sent to client all at once, as you can see in the Wireshark-Screenshots (two links at the end).
- Am I doing something wrong? What am I doing wrong?
- How can I guarantee that replys from TcpServer are not collected and sent all-at-once?
This is the code in client:
for (int i = 1; i <= 10000; i++)
{
if (i % 40 == 0)
{
var dt = DateTime.Now;
var msg = $"CurrentTime;{dt:yyyy-MM-dd HH:mm:ss.fff}";
c.SendAsync(msg);
}
else
{
c.Send("Command_1");
}
}
These are the wireshark screenshots: https://ibb.co/khkJ7pv https://ibb.co/sbcpqsL
Kindly regards.
It sounds like you're running into Nagle's Algorithm, which can be disabled by setting OptionNoDelay
to true
:
https://github.com/chronoxor/NetCoreServer/blob/master/source/NetCoreServer/TcpServer.cs#L110-L116