title: Java/android socket.close() is not realized by server
body: <p>I'm having an issue trying to get a java server to realize an (android/java) client has closed a TCP socket connection. I figured when the client calls <code>close()</code> on the <code>socket</code>, the server would catch an <code>IOException</code>, but this is not the case. <code>t_recv</code> is a thread that receives from <code>BufferedReader in</code>, and <code>t_send</code> sends using a <code>PrintWriter out</code>. Closing <code>in</code> causes a timeout and crash, and closing <code>out</code> doesn't really seem to do anything. The <code>PrintWriter</code> is created in the contructor of the <code>t_send</code> thread, and <code>BufferedReader</code> is create in the contructor of the <code>t_recv</code> thread. Trying to debug this, I created blank <code>run()</code> methods in both threads, and the same behaviour occurs.</p>
  
  <p>An interesting note: the client is an Android application, and whenever the emulator freezes and windows has to force close it, the <code>IOException</code> is caught in the server and the "User x.x.x.x left" message is displayed.</p>
  
  <p>Client closing connection:</p>
  
  <pre><code>try {
      // t_recv.in.close(); - times out and crashes
      // t_send.out.close(); - appears to do nothing
      socket.close();
  } catch (IOException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>Server waiting for client to disconnect:</p>
  
  <pre><code>    for (;;)
      {   
          try {
              while ( (msg = in.readLine()) != null)
              {
                  response = msg;
                  System.out.println(response);
                  server.broadcast(response);
              }
          } catch (IOException e) {
              System.out.println("User '" + socket.getInetAddress().toString() + "' left");
              try {
                  socket.close();
                  out.close();
                  in.close();
              } catch (IOException e1) {
                  e1.printStackTrace();
                  System.exit(-1);
              }
              break;
          }
      }
  </code></pre>
  
  <p>Thanks for your time.</p>