Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help: Why (BufferredReader) br.readLine() stuck?

2,882 views
Skip to first unread message

Liang(Jeremy) Fang

unread,
Nov 30, 2000, 3:00:00 AM11/30/00
to
Hi, all,

I got a tricky problem:
When I tried to get feedback from the server, the client stuck at the
line:
br.readLine();

br is defined as:
br=new BufferedReader(new InputStreamReader(socket.getInputStream()));

the partial codes:
output.writeBytes(...);
while((line = br.readLine()) != null)
data += line + "\n";
......

Thanks a lot!

-FL


Frank

unread,
Nov 30, 2000, 3:00:00 AM11/30/00
to
"Liang(Jeremy) Fang" wrote:
>
> Hi, all,
>
> I got a tricky problem:
> When I tried to get feedback from the server, the client stuck at the
> line:
> br.readLine();
>
> br is defined as:
> br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
<snip>
Most sockets are required to have a buffer where data can be held in the
socket when it arrives and is pending some program to process it, so
using a BufferedReader doesn't make much since since you're double
buffering an input stream. More to the point, a BufferedReader will
continue to read automaticly before returning until either the buffer is
filled, or an end of input stream is reached. ie calling readLine() will
cause the reader to wait indefinately for the server to send enough data
to fill the buffer before even the first line will be returned, but
accessing the input stream directly should fix your problem.
Hope this helps!

Frank

Cat

unread,
Dec 1, 2000, 2:50:46 AM12/1/00
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Also as mentioned in O'Reilly's Java I/O the end of line character
varies from platform to platform. It can be \n\r , \r or \n depending
on your platform. So if you use it in a network situation it's
possible that you could be waiting in vain for the correct
character/s that never come.

Cat

NEW THIS MONTH http://www.ratrobot.com/brainzilla/brainzilla.htm
What's the absolute limit of intelligence in this universe? And why
should I turn of the abflex2000 infomercials long enough to read out
it?
FREE APPLETS http://www.ratrobot.com/java/ratrobot_help.jar JARS
EDITORS CHOICE CartoonPopUps 2.0 . Put cartoon bubbles over your
favourite image link when the cursor is over them.
www.ratrobot.com Articles that challenge your ideas about yourself
and the world you live in.

"Liang(Jeremy) Fang" <lif...@indiana.edu> wrote in message
news:3A272054...@indiana.edu...


> Hi, all,
>
> I got a tricky problem:
> When I tried to get feedback from the server, the client stuck at
> the line:
> br.readLine();
>
> br is defined as:
> br=new BufferedReader(new
> InputStreamReader(socket.getInputStream()));
>

> the partial codes:
> output.writeBytes(...);
> while((line = br.readLine()) != null)
> data += line + "\n";
> ......
>
> Thanks a lot!
>
> -FL

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.8 for non-commercial use <http://www.pgp.com>

iQA/AwUBOibHJCh0Y2LcENUAEQIvawCgw3jPb+BE8xNyllCQX9mRu5on7XcAoOUX
UA43YF1nhfreuXvA1fnP4YdL
=xfgF
-----END PGP SIGNATURE-----

Phil Hanna

unread,
Dec 1, 2000, 3:00:00 AM12/1/00
to
In article <3A272054...@indiana.edu>,

"Liang(Jeremy) Fang" <lif...@indiana.edu> wrote:
> Hi, all,
>
> I got a tricky problem:
> When I tried to get feedback from the server, the client stuck at the
> line:
> br.readLine();
>
> br is defined as:
> br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
>
> the partial codes:
> output.writeBytes(...);
> while((line = br.readLine()) != null)
> data += line + "\n";
> ......
>

output.flush() after the last output.writeBytes() before you start the
while loop. The server is probably waiting for the rest of the request.

--
Phil Hanna
http://www.philhanna.com


Sent via Deja.com http://www.deja.com/
Before you buy.

0 new messages