Why does .Net Socket.Disconnect take two minutes?

前端 未结 5 2078
庸人自扰
庸人自扰 2020-12-31 18:29

I am using .Net\'s socket class and I am using the following code:

socket.Shutdown(SocketShutdown.Both);
socket.Disconnect(true);

This then

5条回答
  •  独厮守ぢ
    2020-12-31 19:13

    It takes 2 min because the server probably did'nt close the socket when it received 0 bytes from the shutdown call of the client.

    So client call shutdown. The server receive 0 bytes. Client call Disconnect : disconnect will wait the close of the socket from the server side. If the server don't close the socket, the disconnect of the client will take 2 min (timeout). If the server close the socket, the disconnect will be almost immediate.

提交回复
热议问题