I'm making a server/client test and want to know if the client is disconnected in java via TCP. I'd rather not do a heartbeat but if I have to, I will.
Asked
Active
Viewed 728 times
1 Answers
1
You have a thread reading from client as a socket input stream. The read may return EOF (-1) if connection is closed by client. Also error could be thrown if there's network problems. In either case you can assume client is disconnected.

irreputable
- 44,725
- 9
- 65
- 93
-
I did it by simply reading and surrounding it in try. Thanks. – Someguynamedpie Jan 21 '11 at 01:48