开发者

C++ TCP connection closing

开发者 https://www.devze.com 2023-04-11 22:56 出处:网络
I have a C++ application called A which open a TCP connection to Application B. Application C knows about this connection and can close the socket from B side.

I have a C++ application called A which open a TCP connection to Application B. Application C knows about this connection and can close the socket from B side. My question is: how can I know if the connection has closed in proper closing, or it is the network co开发者_高级运维nnection problem? Currently I have a timeout which knows when there is no receive, but this not indicate about a proper closing or network connection problem.

I heard that since it is a TCP connection if application C close the connection properly the OS must know about it, do you know how can I know in application A that the connection has closed properly?

if you can attach a c++ sample it will be helpful.


If the connection was closed properly, recv() will return zero. If it was closed improperly, recv() will eventually timeout (although there can be other reasons for that), and send() will eventually return -1 with errno ECONNRESET or whatever it's called.

0

精彩评论

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

关注公众号