When to use setSoLinger

It allows you to control a TCP socket close() method. eg.

socket.setSoLinger(true, 5000);
...
socket.close();

the socket.close() method will block until the the data that is still in the send-buffer is sent to the other end and acknowledged. If the linger delay has passed (5000 milliseconds in this case), the socket will be forced to be closed.