W3C home > Mailing lists > Public > www-talk@w3.org > January to February 1998

Newbie: Determining end of file

From: Chris <chris@surewould.com>
Date: Fri, 13 Feb 1998 16:48:38 -0500
Message-ID: <34E4BFB6.3A64@surewould.com>
To: 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
Received on Friday, 13 February 1998 16:47:37 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 27 October 2010 18:14:23 GMT