开发者

How would I check if the client is no longer connected via TCP in Java?

I'm making a server/client test and want to know if the client is disconnected in j开发者_运维技巧ava via TCP. I'd rather not do a heartbeat but if I have to, I will.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜