deshapriya debesh
deshapriya debesh

Reputation: 121

tcp closesocket method of winsock generating reset (RST)

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.

Upvotes: 4

Views: 1856

Answers (2)

user11082348
user11082348

Reputation: 19

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

Ex: shutdown(clisocket, SD_BOTH);

Upvotes: 1

user207421
user207421

Reputation: 310860

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.

Upvotes: 2

Related Questions