tcp closesocket method of winsock generating reset (RST)

1.6k views Asked by At

Windows socket close(closesocket) function generates RST.

On linux when I call close function to close a tcp socket it goes through fin/ack from both client server and the socket gets closed.

But on windows winsock, whenever i call closesocket it always generates RST message.

I tried using shutdown call. It is generating FIN. But finally I have to call closesocket and it sends RST.

Is there a way to call closesocket to release socket resources without sending RST message.

2

There are 2 answers

0
user207421 On

There are several things that can cause closesocket() to send an RST instead of a FIN:

  1. Calling it when there is unread data pending in the socket receive buffer.
  2. Calling it after you have set the SO_LINGER option to 'on' with a zero timeout.
2
user11082348 On

If there are no more data to send and/or receive, you can use 'shutdown()'.

Ex: shutdown(clisocket, SD_BOTH);