How to disable Nagle algorithm / enable TCP_NoDelay?
Hi, Dear Developers! I am trying to make TCP client on C++, by using this example: link:( https://wiki.unrealengine.com/Third_Party_Socket_Server_Connection ). When I send messages to the Server with small intervals, on Server I receive merged Posts like this:
To solve this problem I was going to disable Nagle algorithm / enable TCP_NoDelay, but don't know how. I was looking for method FSocket.setNoDelay(true) or something similar, but have nothing. Who know, where I can find this option for TCP Sockets?
This is for windows only:
If you can get the Winsock from your FSocket instance then you can disable Nagle's algorithm by yourself. Unfortunately the Winsock is not a member of FSocket, but it is a member of FSocket's Windows specific derivation FSocketBSD. But Unreal Engine does not expose this type so you can't use it in your code without changing the engine source.
So here's how to disable Nagle's algorithm without changing the engine source :)
Here are the Winsock error codes in case you need to debug something. This works because FSocketBSD is derived from FSocket and the Winsock is the first member of FSocketBSD. Since member variables are laid out in memory in the order they are defined (*most of the time), the first value in memory after your FSocket will be the first member of FSocketBSD. I said *most of the time because the layout of memory can depend on the compiler and compiler options. This will also not work if future Unreal version move the Winsock so that it's not the first member of FSocketBSD, though this can be fixed by simply moving the pointer to it's new location.
Follow this question
Once you sign in you will be able to subscribe for any updates here