When to use setTcpNoDelay

It allows you to enable or disable Nagle’s algorithm, which is used to conserve bandwidth by minimizing the number of data segments that are sent. When TcpNoDelay is enabled, data will not be sent immediately, instead it waits for more write calls and tries to squeeze in as much as possible into a packet before sending. If you know your app should be using small packets anyway (eg. chat apps), and send them as soon as possible (no wait), at the cost of more bandwidth, then you can disable nagle’s algorithm:

   setTcpNoDelay(true)

Nagle’s algorithm is described in RFC896.