Skip to Main Content

Java APIs

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!

Socket read fails but write is successful. Why?

843790Jan 15 2007 — edited Jan 17 2007
Hi once more!

I have a Java application, reading and writing from/to a client socket:
...
InputStream is = socket.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
...
i = br.read();
...
If i is equal to -1, it means there's no connection or that somehow the connection is unavailable right? So, how come is it possible to write to the socket's output stream with success after that read( ) returning -1? Shouldn't it also fail?

I'm trying a "persistent" TCP connection, so I use that condition (read () == -1) to determine when the connection is down (read() is only blocking a certain amount of time).

Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 14 2007
Added on Jan 15 2007
7 comments
1,692 views