5

Is anyone aware how to configure nagle's algorithm (on or off) while using socket.io?
Is this option even provided with socket.io?
I am assuming that the default behavior is configured to use nagle's algorithm (please correct me if I am wrong).

I would ideally like to configure nagle's algo (on/off) while using socket.io as needed in different applications - regardless of which web/app server I may be using.

Thanks!

ali haider
  • 19,175
  • 17
  • 80
  • 149

2 Answers2

3

As per Guillermo Rauch, Nagle's algorithm is turned off by default for web sockets in socket.io. I will submit a request to make this configurable (hopefully this will be looked at in a future release).

Thanks Guillermo.

ali haider
  • 19,175
  • 17
  • 80
  • 149
1

The nagle algorithm can be switched of

int socket_descriptor;  
BOOL bOptVal = TRUE;
int bOptLen = sizeof(BOOL);
// get a socket:
socket_descriptor = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
/* ... bind the socket, listen to it
    .
    .
*/
// set the socket to non-blocking mode:
ioctlsocket(socket_descriptor, FIONBIO, 1);

// disable nagle:
setsockopt(socket_descriptor, IPPROTO_TCP, TCP_NODELAY, (char*)&bOptVal, bOptLen);

Edit: in .NET it is the Socket.NoDelay property.

in socket.io the nagle algorithm is already disabled for websockets and disabling it for other transports is beeing discussed (as of April 2012).

Arno
  • 4,994
  • 3
  • 39
  • 63
  • +1 for adding the info - good to see the functionality was added. – ali haider Jul 16 '12 at 14:01
  • This answer is incorrect. It would be correct if the question was about traditional "BSD" sockets, a.k.a. TCP sockets, a.k.a. winsock, etc., but the question is about the poorly-named yet very powerful "socket.io" library which you can learn more about at: [http://socket.io/](http://socket.io/) – corecursion Oct 03 '12 at 22:39
  • @ShawnYarbrough: Thanks for the hint. I corrected the information and added the current state of the _socket.io_ nagle discussion – Arno Oct 08 '12 at 07:55