title: Java socket exception: recv failed
body: <p>This is basically the picture:
  I have a server and a client (operating through localhost). Server creates a clientthread for each connection. this new thread blocks on read waiting for messages from client. At will, i can deactivate the server through the GUI, which sends (from a main thread) "disconnect" to the client, and then closes the output stream, to wake up the blocked clientthread, which in turn finishes up by closing the socket (I believe this closing is unnecessary after closing outputstream but anyway).</p>
  
  <p>Client side:
  After connection request, it sleeps 10 seconds, writes a disconnect message and reads the answer char by char.</p>
  
  <p>The problem:</p>
  
  <p>After deactivating the server within that 10 second client sleep time, client reads the "disconnect" message correctly from the server. However, If I just add a dummy print for each char read (inside the while loop), the result of the final read is varying.
  Sometimes it will read the server's "disconnect" correctly, sometimes it will read "disco", or a similar variation, and throw this exception:</p>
  
  <p>"Java exception : "Software caused connection abort: recv failed"</p>
  
  <p>Any suggestions as to why adding a few prints creates this result? I would assume having a closed socket on the other end wouldn't have an effect on reading the message.
  The other threads I found about recv errors mentioned timeouts, which I'm guessing shouldn't really be happening when using localhost?</p>