title: java.net.Socket TCP keep-alive usage
body: <p>How to use <a href="https://docs.oracle.com/javase/8/docs/api/java/net/Socket.html#setKeepAlive-boolean-" rel="nofollow"><code>java.net.Socket</code> <strong><code>setKeepAlive(boolean b)</code></strong></a> API?</p>
  
  <p>I am hosting a simple server using <code>Socket</code>. 
  The clients can connect and send data. I will not close the connection unless the client sends end of stream. The client can continue to hold a connection for any length of time. Data transfer will be going on, but suddenly I see that there is a connection loss without any logs whatsoever. Once the client is restarted (not server), the transmission begins again.
  I am not setting any <code>timeout</code> as by default it is infinity. I want to understand what <code>setKeepAlive</code> actually does so that I will be able to decide whether I need to set that to <code>true</code>. 
  Can someone help me understand the same? thanks.</p>