Send a zero-data TCP/IP packet using Java

我只是一个虾纸丫 提交于 2019-12-05 18:01:38

If you just want to quickly detect silently dropped connections, you can use Socket.setKeepAlive( true ). This method ask TCP/IP to handle heartbeat probing without any data packets or application programming. If you want more control on the frequency of the heartbeat, however, you should implement heartbeat with application level packets.

See here for more details: http://mindprod.com/jgloss/socket.html#DISCONNECT

There is no such thing as an empty TCP packet, because there is no such thing as a TCP packet. TCP is a byte-stream protocol. If you send zero bytes, nothing happens.

To detect broken connections, short of keepalive which only helps you after two hours, you must rely on read timeouts and write exceptions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!