简体   繁体   中英

C++ TCP connection closing

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

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