1

Topic: closesocket vs shutdown

I try sockets under Windows in a local network (SOCK_STREAM, WSA_FLAG_OVERLAPPED).
The client does 1000 connections to the server. Then closes 1000 connections on button click.
Sending of the data is not produced, but on each socket c asynchronous WSARecv.
And so. If I on the client cause simply closesocket (s) for each of 1000 sockets on the server all is caught rarely 1000 , but in the core on the average 50 - 400 connections it is necessary to hang (WSARecv the byte) does not signal about a zero amount. And it is not pleasant to me.
If I on the client do shutdown (s, SD_SEND), and then closesocket (s) for each of 1000 sockets on the client the first 600-800 sockets receive  at once, remained are closed slowly in flow of 5-15 seconds.
This normal behavior of sockets at closing?:confused:

2

Re: closesocket vs shutdown

RickD
shutdown communication by means TCP/IP of the protocol (pair of packets FIN/ACK), thus other side closes will authentically know about communications closing.
the correct method is a call shutdown for end of communications and then closing of a socket with the help close.

If I on the client cause simply closesocket (s) for each of 1000 sockets on the server all is caught rarely 1000 , but in the core on the average 50 - 400 connections it is necessary to hang (WSARecv the byte) does not signal about a zero amount. And it is not pleasant to me.

through what that time they "die" depending on adjustments of parameters () TCP/IP

If I on the client do shutdown (s, SD_SEND), and then closesocket (s) for each of 1000 sockets on the client the first 600-800 sockets receive  at once, remained are closed slowly in flow of 5-15 seconds.

the Remained sockets I wait for end of transfer from the server (you made shutdown (s, SD_SEND), instead of SD_BOTH)
SD_SEND Speaks about yours  to stop sending, but not reception (if you do not transfer the data that it does not mean at all that the auxiliary packets TCP are transferred).

3

Re: closesocket vs shutdown

Essence of a problem what even by a call shutdown (s, SD_SEND) approximately percent of 60 sockets on other side others are closed almost instantly, and slowly in flow of tens seconds. Delivered WireShark, I will try to look, whether goes and accepted FIN at once. And it in local that networks! The router somehow can influences behavior?
In this connection there was a question. For example on the server it is a lot of clients, the client does connection rupture, but the server  or something with a network, and breaks off at itself connection with a time delay. The client does not know about it, does reconnect, the server processes it before rupture of the previous connection and at the server some time is 2 connections to the client. Such it is possible?

4

Re: closesocket vs shutdown

[q=RickD] And it in local that networks! The router somehow can influences behavior?

Well and  kol-in packets, in WireShark all it is visible.

Such it is possible?

Basically - yes, but in the big networks it is improbable (long ). Invalid connection dies by itself on the sly.