title: Java SocketException Broken pipe
body: <p>I am doing a client to server Log-in communication.</p>
  
  <p>I met a java.net.SocketException: broke Pipe at Server end. And I have narrowed the 
  problem to <strong>one single line at the client end</strong>. If I move a position for this line,
  the code works. plese see the following code.</p>
  
  <p>Client End:</p>
  
  <pre><code>    Socket socket = new Socket(Const.destIp, 12101);
      ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
      out.writeObject(this.message);              
      out.close();//Line that cause problem   
      ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
      ServerToClientLogin msg = (ServerToClientLogin) in.readObject();
      //out.close();//move it to here, problem solved
      in.close();
      socket.close();
  </code></pre>
  
  <p>Server end:</p>
  
  <pre><code>   while (true) {
       socket = _serverSocket.accept();
       in = new ObjectInputStream(socket.getInputStream());
       msg = (ClientToServerLogin) in.readObject();
  
       ServerToClientLogin msgToSend = null;
       out = new ObjectOutputStream(socket.getOutputStream());
       msgToSend = handleLoginRequest(msg);
       if(msgToSend != null) out.writeObject(msgToSend);
  
       try { in.close(); } catch (IOException e) {e.printStackTrace();}
       try { out.close();} catch (IOException e) {e.printStackTrace(); }
       try { socket.close();} catch (IOException e) {e.printStackTrace();}
  
  }
  </code></pre>
  
  <p>Since readObject and writeObject are blocking call, I have no idea why close it earlier would case such problem.</p>