How do I control the amount of time a socket will linger before resetting?
When a socket wishes to terminate a connection it can \"linger\", allowing unsent data to be transmitted, or it can \"reset\" which means that all unsent data will be lost.
We can explicitly set a delay before a reset is sent, giving more time for data to be read, or you can specify a delay of zero, meaning a reset will be sent as the java.net.Socket.close() method is invoked.The socket option SO_LINGER controls whether a connection will be aborted, and if so, the linger delay.
Use the java.net.Socket.setSoLinger method, which accepts as parameters a boolean and an int.
The boolean flag will activate/deactivate the SO_LINGER option, and the int will control the delay time.