title: Sockets: BufferedReader readLine() blocks
body: <p>I am using <code>BufferedReader.readLine()</code> method to read a response from a remote server (which is written in C and I have no access to source code).</p>
  
  <pre><code>BufferedReader br = new BufferedReader(new InputStreamReader(in));
  String line;
  while((line = br.readLine())!=null){
      [...]
  }
  </code></pre>
  
  <p>But it always blocks at the last line until it times out. So I used the following code:</p>
  
  <pre><code>int b;
  while(true){
     b = in.read;
     [...]
  }
  </code></pre>
  
  <p>and I found out that the last byte read has an integer value of 13, which I think it is a carriage return, right?</p>
  
  <p>So why the <code>readLine</code> method blocks? How does the server usually signal an end of stream is reached? Thanks.</p>