Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

InputStream keeps reading forever

807591May 11 2008 — edited May 12 2008
Hi,

I have a 'little' problem with input stream. I have a Telnet connection established and I'm reading the input I receive. I read some input and then I send commands. I'm reading the input inside a while loop like this one:
InputStream in = telnet.getInputStream();
char ch = '';

while (condition) {
    ch = (char)in.read();
}
The problem is that, when the input is over, in doesn't get out of read and it stays there forever. It doesn't event returns -1, the last char read, anything, it simply doesn't gets out of there. Is there a way to know when there's no more input to avoid this from happening? I can't use read(byte[]) because the input varies and I can't know how many data will be received. There's also no indicator of the end of data like: EOF or -1.

I will appreciate any help.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 9 2008
Added on May 11 2008
9 comments
1,345 views