title: Java, sockets, BufferedReader, and readline hang ... :(
body: <p>I'm not a Java programmer at all.  I try to avoid it at all costs actually, but it is required that I use it for a class (in the school sense).  The teacher requires that we use Socket(), BufferedReader(), PrintWriter() and various other things including BufferedReader()'s readLine() method.</p>
  
  <p>Basically, this is the problem I'm having.  The documentation clearly states that readLine should return a null at the end of the input stream, but that's not what's happening.</p>
  
  <pre><code>Socket link       = new Socket(this.address, 80);
  BufferedReader in = new BufferedReader( new InputStreamReader( link.getInputStream() ));
  PrintWriter   out = new PrintWriter(    new PrintWriter(       link.getOutputStream(), true ));
  
  out.print("GET blah blah blah"); // http request by hand
  out.flush(); // send the get please
  
  while( (s=in.readLine()) != null ) {
  
      // prints the html correctly, hooray!!
      System.out.println(s);
  }
  </code></pre>
  
  <p>Instead of finishing at the end of the HTML, I get a blank line, a 0 and
  another blank line and then the next in.readLine() hangs forever.  Why?
  Where's my null?</p>
  
  <p>I tried out.close() to see if maybe Yahoo! was doing a persistent http
  session or something (which I don't think it would without the header that
  we're willing to do it).</p>
  
  <p>All the Java sockets examples I'm finding on the net seem to indicate the
  while loop is the correct form.  I just don't know enough Java to debug
  this.</p>