title: How do I set read timeouts on java Socket/SSLSocket?
body: <p>If I have a connected socket and and it is waiting(blocking) to receive some data from the remote machine but somehow or other, the remote machine loses its connection, how can I make it such that it stops blocking but times out after a certain period of time without receiving any data? I'm using a Scanner object to read data from the socket and a PrintWriter object to write,</p>
  
  <pre><code>// Get InputStream
  scanner = new Scanner( clientSocket.getInputStream() );
  // Get OutputStream
  printWriter = new PrintWriter( clientSocket.getOutputStream(), true );
  </code></pre>