简体   繁体   中英

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 beginning 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM