title: Reading all input from a socket continuously
body: <p>I'm writing a simple Java client/server application for my own use. It should allow clients to send single line text messages and read multiline responses. This kind of communication should be repeatable many times using the same connection. </p>
  
  <p>This is what I have in the client for reading responses:</p>
  
  <pre><code>BufferedReader input = new BufferedReader(new InputStreamReader(server.getInputStream()));
  String line;
  while ((line = input.readLine()) != null) {
      // processing here
  }
  </code></pre>
  
  <p>The problem with this is that readLine() blocks once the server sends the first response back and the client cannot send new messages because of that. This is understandable. A naive workaround could be making the server signal the end of its output by sending some kind of a known special string value which the client would then recognize and end the reading loop. However, is there a better solution to this problem?</p>