title: Socket stream hangs when using IOUtils.copy()
body: <p>I want to send an <code>InputStream</code> containing XML from the client to a server. Said server manipulates the XML stream using <code>Streaming API for XML (StAX)</code> and sends it back to the client.</p>
  
  <p>I mange to send the XML to the server, the client receives the answer, but doesn't exit because the server never finishes reading the <code>InputStream</code> form the client.
  But when the server is just dumping the input to <code>System.out</code> instead of sending something, reading finishes...</p>
  
  <p><em><strong>edit</em></strong> I forgot to mention that <code>IOUtils.copy()</code> is running in two separate threads on the client.</p>
  
  <p>Here some code to reproduce this, I've replaced the <code>StAX</code> part with <code>IOUtils.copy()</code> on the server.</p>
  
  <p><strong>Server</strong></p>
  
  <pre><code>ServerSocket serverSocket = new ServerSocket(port);
  Socket clientSocket = serverSocket.accept();
  
  InputStream in = clientSocket.getInputStream();
  OutputStream out = clientSocket.getOutputStream();
  IOUtils.copy(in, out);
  </code></pre>
  
  <p><strong>Client</strong></p>
  
  <pre><code>Socket socket = new Socket(host, port);
  FileInputStream fin = new FileInputStream(file);
  OutputStream out = socket.getOutputStream();
  IOUtils.copy(fin, out)
  
  InputStream in = socket.getInputStream();
  IOUtils.copy(in, System.out)
  </code></pre>