为什么净Socket.Disconnect需要两分钟呢? [英] Why does .Net Socket.Disconnect take two minutes?
问题描述
我使用的.Net的Socket类,我用下面的code:
socket.Shutdown(SocketShutdown.Both);
socket.Disconnect(真正的);
这则阻止了整整两分钟。我已经指定了正确的,因为我要立即重新使用的插座,并重新建立连接。我是否有关闭调用在那里,或不是块两分钟。我唯一能做的就是通过虚假断开。但我想重新使用套接字。
任何想法?
更新:
我已经阅读了codeS。我已经设置了DontLinger选项。它并不能帮助。
更新2:
我添加了一个网络跟踪为每个请求:
跟踪1:使用DontLinger选项
的System.Net.Sockets详细:0:[4668]插孔#5009246 ::插座(网间#2)
的System.Net.Sockets详细:0:[4668]退出插槽#5009246 ::插座()
的System.Net.Sockets详细:0:[4668]插孔#5009246 ::连接(EEE:NNNN#-2063562120)
的System.Net.Sockets信息:0:[4668]插孔#5009246 - 从aaa.bbb.ccc.ddd.eee创建的连接:NNNNN到www.xxx.yyy.zzz:MMMM。
的System.Net.Sockets详细:0:[4668]退出插槽#5009246 ::连接()
的System.Net.Sockets详细:0:[4668]插孔#5009246 ::断开()
的System.Net.Sockets详细:0:[4668]退出插槽#5009246 ::断开()
跟踪2:使用shutdown(SocketShutdown.Both);
的System.Net.Sockets详细:0:[0300]插孔#5009246 ::插座(网间#2)
的System.Net.Sockets详细:0:[0300]退出插槽#5009246 ::插座()
的System.Net.Sockets详细:0:[0300]插孔#5009246 ::连接(DDD:EEEEE#-2063562120)
的System.Net.Sockets信息:0:[0300]插孔#5009246 - 从一个aaa.bbb.ccc.ddd创建的连接:EEEE到www.xxx.yyyy.zzzz:NNNNN。
的System.Net.Sockets详细:0:[0300]退出插槽#5009246 ::连接()
的System.Net.Sockets详细:0:[0300]插孔#5009246 ::关机(无论#2)
的System.Net.Sockets详细:0:[0300]退出插槽#5009246 ::关机()
的System.Net.Sockets详细:0:[0300]插孔#5009246 ::断开()
的System.Net.Sockets详细:0:[0300]退出插槽#5009246 ::断开()
原来有是控制多久断开需要一些注册表项。它有事情做与WinSock2中的API。
I am using .Net's socket class and I am using the following code:
socket.Shutdown(SocketShutdown.Both);
socket.Disconnect(true);
This then blocks for exactly two minutes. I have specified true because I am going to reuse the socket immediately and re-establish the connection. Whether I have the Shutdown call in there or not it blocks for two minutes. The only thing I can do is pass false to disconnect. But I want to reuse the socket.
Any ideas?
UPDATE:
I have read the codes. I have set the DontLinger option. It does not help.
UPDATE 2:
I have added a network trace as per request:
Trace 1: Using the DontLinger option
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()
Trace 2: Using the Shutdown(SocketShutdown.Both);
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()
Turns out there is some registry entry which controls how long a disconnect takes. It has something to do with the WinSock2 api.
这篇关于为什么净Socket.Disconnect需要两分钟呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!