Skip to content
Snippets Groups Projects
Commit 6fe719b8 authored by Brutzman, Don's avatar Brutzman, Don
Browse files

improved comments

parent 0283100a
No related branches found
No related tags found
No related merge requests found
package webexample; package webexample;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
/** /**
* A very simple web reading example that won't work in some circumstances. * A very simple http web-page reading example that won't work in some circumstances.
* But it will in some others. * But it will in some others.
* *
* @author mcgredo * @author mcgredo
...@@ -40,24 +39,22 @@ public class WebExample { ...@@ -40,24 +39,22 @@ public class WebExample {
ps.print("\r\n\r\n"); ps.print("\r\n\r\n");
ps.flush(); ps.flush();
// Up until now we have been reading one line only. But // Up until now we have been reading one line only.
// a web server will write an unknown number of lines. We // But a web server will write an unknown number of lines.
// read until the transmisson ends. // So now we read until the transmisson ends.
InputStream is = socket.getInputStream(); InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is); InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr); BufferedReader br = new BufferedReader(isr);
String line; String line;
int count = 0; int count = 0;
while((line = br.readLine()) != null) while((line = br.readLine()) != null) // read from BufferedReader br one line at a time
{ {
count++; count++;
System.out.println(count + ": " + line); System.out.println(count + ": " + line);
}
}
System.out.println("web server message finished"); System.out.println("web server message finished");
} }
catch(Exception e) catch(Exception e)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment