Why does .Net Socket.Disconnect take two minutes?

前端 未结 5 2089
庸人自扰
庸人自扰 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:05

    That may be to the Linger option. See here for more information: Graceful Shutdown, Linger Options, and Socket Closure

    in .NET, you can change it with the Socket.SetSocketOption method.

    EDIT: if it's not the Linger option, you should try to enable full socket traces, here is a .config sample:

    
      
        
        
          
            
              
            
          
        
    
        
          
        
    
        
          
        
     
    

    EDIT: or you can hit what's called the TIME_WAIT, described here: Please explain the TIME_WAIT state which is 120ms. It's generally better to use Close() with the SocketOptionName.ReuseAddress rather than to use Disconnect(true). See comments here as well (in the comments section).

提交回复
热议问题