Home > Software engineering >  How to gracefully closes the connection
How to gracefully closes the connection

Time:09-27

The recv function, the return value of the official document mentioned "gracefully closes the connection, it returns 0", but I'm on the client side closesocket, server side still get 1

[code=TXT] If the connection has then gracefully closed, the return value is zero. [/code]

CodePudding user response:

To the assure that all data is sent and received on a connected socket before it is closed, an application should use shutdown To close the connection before calling closesocket.

CodePudding user response:

1 is SOCKET_ERROR, and WSAGetLastError classification error information

CodePudding user response:


Close the connection after receive the last message
And don't
Close the connection after sending the last message,

CodePudding user response:

SD_BOTH shutdown (fd)

CodePudding user response:


How to change the code to send and receive test,
Elegant and sometimes there is no use, your server is elegant, others client various environment, suddenly disconnected, you can't let customer elegant,

CodePudding user response:

Network programming sometimes server or client is not very good testing to disconnect, the general approach is to set the timeout mechanism, over a period of time not to receive each other's heartbeat synchronous package that the other party has been disconnected, the server should take the initiative to disconnect, especially in the GPRS network,
  • Related