0

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.

1 Answer 1

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.

1
  • I did it by simply reading and surrounding it in try. Thanks. Jan 21, 2011 at 1:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.