我使用的.Net的Socket類,我用下面的代碼:爲什麼.Net Socket.Disconnect需要兩分鐘?
socket.Shutdown(SocketShutdown.Both);
socket.Disconnect(true);
這就塊整整兩分鐘。我指定了true,因爲我將立即重用套接字並重新建立連接。無論是否有關機呼叫,它都會阻塞兩分鐘。我能做的唯一事情就是傳遞錯誤來斷開連接。但我想重用套接字。
任何想法?
UPDATE:
我已閱讀代碼。我已經設置了DontLinger選項。它沒有幫助。
更新2:
我已經加入網絡跟蹤按請求:
跟蹤1:使用DontLinger選項
System.Net.Sockets Verbose: 0 : [4668] Socket#5009246::Socket(InterNetwork#2)
System.Net.Sockets Verbose: 0 : [4668] Exiting Socket#5009246::Socket()
System.Net.Sockets Verbose: 0 : [4668] Socket#5009246::Connect(eee:nnnn#-2063562120)
System.Net.Sockets Information: 0 : [4668] Socket#5009246 - Created connection from aaa.bbb.ccc.ddd.eee:nnnnn to www.xxx.yyy.zzz.:mmmm.
System.Net.Sockets Verbose: 0 : [4668] Exiting Socket#5009246::Connect()
System.Net.Sockets Verbose: 0 : [4668] Socket#5009246::Disconnect()
System.Net.Sockets Verbose: 0 : [4668] Exiting Socket#5009246::Disconnect()
跡線2:使用關機(SocketShutdown。都);
System.Net.Sockets Verbose: 0 : [0300] Socket#5009246::Socket(InterNetwork#2)
System.Net.Sockets Verbose: 0 : [0300] Exiting Socket#5009246::Socket()
System.Net.Sockets Verbose: 0 : [0300] Socket#5009246::Connect(ddd:eeeee#-2063562120)
System.Net.Sockets Information: 0 : [0300] Socket#5009246 - Created connection from aaa.bbb.ccc.ddd:eeee to www.xxx.yyyy.zzzz:nnnnn.
System.Net.Sockets Verbose: 0 : [0300] Exiting Socket#5009246::Connect()
System.Net.Sockets Verbose: 0 : [0300] Socket#5009246::Shutdown(Both#2)
System.Net.Sockets Verbose: 0 : [0300] Exiting Socket#5009246::Shutdown()
System.Net.Sockets Verbose: 0 : [0300] Socket#5009246::Disconnect()
System.Net.Sockets Verbose: 0 : [0300] Exiting Socket#5009246::Disconnect()
我們可以看到一些周圍的代碼嗎?有可能是由於其他原因導致延遲,例如循環或阻塞呼叫。 – 2010-12-07 19:29:15