[11108] in www-talk@info.cern.ch

home help back first fref pref prev next nref lref last post

Newbie: Determining end of file

daemon@ATHENA.MIT.EDU (Chris)
Fri Feb 13 17:18:37 1998

Date: Fri, 13 Feb 1998 16:48:38 -0500
From: Chris <chris@surewould.com>
Reply-To: chris@surewould.com
To: www-talk@w3.org
Resent-From: www-talk@w3.org

I'm trying to write a mini-browser in Java. I can send out the HTTP
request OK, but my code that receives the file doesn't know when to
quit. It looks (roughly) like this:

	// [in = the input stream of the socket I create]
	// [outfile = the file to dump the response into]
	String line;
	while ((line = in.readLine()) != null)
		outfile.println(line);

Pretty basic. But it doesn't always work. Sometimes it works, sometimes
it hangs forever, waiting for the last read. It depends on the page, and
it's consistent (if it hangs on a certain page, then it *always* hangs
on that page). Reading in one character at a time is inconsistent also.

Should I be reading the Content-Length value and using it, instead of
this lazy 'read-until-you-tell-me-not-to' approach? 

Thanks,
Chris


home help back first fref pref prev next nref lref last post