This problem has plagued me several times, has not had time to study, today studies.
- First write a simple socket TCP program, the connection is successful and then shut down the server and then use the client various operations to see what the situation
Tests show
(1) The client is already connected, and when the server closes the program, the client calls the Send function to fail, WSAGetLastError () returns 10054 (the remote host forcibly shuts down an existing connection)
(2) The client is already connected, when the client closes the program, the server calls the RECV function to receive the failure, WSAGetLastError () returns 10054 (the remote host forcibly closes an existing connection), when the socket for this client calls the Select function, Will immediately return to readable.
(3) The client is already connected, and when the server closes the program, the client calls the RECV function to receive the failure, WSAGetLastError () returns 10054
- About client wire break re-connect
The rough practice is that when the client calls send or recv fails, then WSAGetLastError () determines the error number and then closes the socket. Create a socket again. Then do a connect operation.
Attached below is a one-to-many chat supported by the source server that I wrote based on socket streaming sockets. Socket-related communications are all used with Windows APIs. Used for beginners ' learning.
SOURCE download
About socket TCP wire break re-connect