Article View: comp.lang.java.programmer
Article #441Re: IP Socket programming with BufferedReader
From: shoban
Date: Wed, 04 Feb 1998 00:00
Date: Wed, 04 Feb 1998 00:00
48 lines
2613 bytes
2613 bytes
There should be a method for specifying when the data orginating from the
server stops. I the case you are communicating with Web server (e.g., GET
www.yahoo.com HTTP/1.0), the server terminates connection with an empty line
or specifies the number of bytes that it will be sending sending before
termination.
If there is no way of finding out when the data stream ends, read all the
data that comes in. When the server closes the socket, you will get an
exception.
Instead of using a 'for' loop try using a do-while construct:
try
{
do
{
readLine();
}while(true);
}
catch(exception)
{
}
This way, you can get all the data.
Geoffrey L. Goetz wrote:
> I am having a problem with implementing the readLine() method of the
> BufferedReader. I have an IP socket server written in Delphi C/S 3.0
> running on NT and want to send/receive a string of text to/from this ip
> server with a java client application (not an applet). This java
> application will eventually be a servlet. But first I need to get some
> of the basics of Java based IP programming under control.
>
> The problem is that the readLine() quits once a carriage return and/or a
> line feed is 'hit'. So I decided to create a for loop that will execute
> 100 times until an exception is raised which will force an exit. (BAD
> CODE) Don't like counting on the exception and I never know if 100
> executions of readLine() will be enough. The server application
> (Delphi/NT) will close the connection once the data is sent back if this
> helps...
>
> Any other (GOOD CODE) ways of implementing this? For the example I am
> using port 80 on yahoo's web server and sending a request for the
> default page of the server, but my needs are not URL based. I need to
> send and receive multiple strings to and from an open ip socket on a
> server (non standard ports).
Technical Details
Message-ID:
<34D86C96.FC3A3138@thinkbn.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<34D808EB.51ECE550@columbus.NOSPAM.rr.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10a146,ba5f46377b9766a3 X-Google-Attributes: gid10a146,public X-Google-Thread: f74b3,ba5f46377b9766a3 X-Google-Attributes: gidf74b3,public From: shoban <shoban@thinkbn.com> Subject: Re: IP Socket programming with BufferedReader Date: 1998/02/04 Message-ID: <34D86C96.FC3A3138@thinkbn.com> X-Deja-AN: 321989616 Content-Transfer-Encoding: 7bit References: <34D808EB.51ECE550@columbus.NOSPAM.rr.com> To: "Geoffrey L. Goetz" <ggeoffre@columbus.NOSPAM.rr.com> Content-Type: text/plain; charset=us-ascii Organization: Think Business Networks Pvt. Ltd Mime-Version: 1.0 Newsgroups: comp.lang.java.programmer,borland.public.jbuilder.java.language