开发者

How to detect socket Exception when internet connection is not there

Hi I have created a socket server and client program. My socket server is running on different computer and in my computer socket client is there. It works fine But the problem is that if there is no internet connection from the b开发者_Go百科eginning in client computer then during I create socket connection I gets error.

only once i will create socket connection and then for infinite I am trying to send data to server and server receives the data perfectly. but in between these if at any point of time I disconnect client internet then also I am unable to get any exception so that I can know that my internet connection is disconnected or my socket connection is not present or my socket connection became null . So how to detect the internet connection failure at this point of time...

Thanks Sunil Kumar Sahoo


You should use the setKeepAlive(true) method. Then you should configure your keep-alive timeout per your OS. I remember that Windows had a very large keep-alive timeout so merely setting the keep-alive option would do no good.

Another option is to implement the keep-alive functionary at the application level yourself, instead of relying on the TCP layer to do this checking.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜