I am not a Java programmer at all. I try to avoid it at all costs in fact, but it is required that I use it for the class (in a school sense). The teacher requires us to use Socket (), BufferedReader (), PrintWriter () and other other things, including the BufferedReader () readLine () method.
Basically, this is the problem I am facing. The documentation clearly states that readLine should return zero at the end of the input stream, but this is not what happens.
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); }
Instead of ending at the end of the HTML, I get an empty string, 0 and another empty string, and then the next in.readLine () hangs forever. What for? Where is my null?
I tried out.close () to find out if Yahoo! did a permanent http session or something (which I donβt think that without a header we are ready to do this).
All the examples of Java sockets that I find on the network seem to indicate while the loop is the correct form. I just don't know enough Java to debug this.
jettero
source share