开发者

Network connection in C++

开发者 https://www.devze.com 2023-04-10 21:00 出处:网络
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.

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 socke开发者_JS百科t 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?

0

精彩评论

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