简体   繁体   中英

Network connection in C++

In a c++ application (which I didn't write) It uses network connection. in a loop it is always check if the connection is still available. if I'm taking out the LAN cable, my application just fails because a timeout occured. Is I know the socket number and connection info. is there any way to know that It is a network error?

Unplugging the cable is not necessarily a "network error" per se. A TCP connection can easily survive across the disconnection if it's temporary enough not to reach the timeout set on the TCP connection, which is done on the socket in your case. So you can set the timeout lower, or have some other logic that tests the state of the underlying link (physical interface), but this is rarely done in practice, and usually the TCP timeout is good enough for most purposes. Why is it not good enough for yours?

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