插座不要真的关闭。请帮助微软MVP! [英] Socket dont really close. Please help microsoft MVP!

查看:72
本文介绍了插座不要真的关闭。请帮助微软MVP!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这让我发疯了!


请,如果有人可以帮助我。


我正在测试一个版本简单的套接字客户端。

在我的测试中,我只是打开并关闭一个连接(在一个循环中)到我的本地IIS

服务器(端口80)


使用System.Net.Sockets;


for(int I = 0; I< 5000; I ++)

{

TcpClient myClient = new TcpClient();

try

{

myClient.Connect(" 127.0.0.1" ;,80)

}

catch(Exception ex){MessangeBox.Show(ex.ToString()); }

myClient.Close()

} //结束

一切顺利,数千个连接被打开并关闭,直到

出现此错误....


[System.Net.Sockets.SocketException:每个套接字地址只有一种用法

(协议/网络地址/端口)通常是允许的]


出现此错误后,我执行netstat -a命令和行(下方)

出现数千个时间,下面的行只是

完整列表中的一小部分。


TCP asusis-dsgn:3505 localhost:80 TIME_WAIT

TCP asusis-dsgn:3506 localhost:80 TIME_WAIT

TCP asusis-dsgn:3507 localhost:89 TIME_WAIT

TCP asusis-dsgn:3508 localhost:89 TIME_WAIT

TCP asusis-dsgn:3509 localhost:89 TIME_WAIT

TCP asusis-dsgn:3510 localhost:89 TIME_WAIT

TCP asusis-dsgn:3511 localhost:89 TIME_WAIT

TCP asusis-dsgn:3512 localhost:89 TIME_WAIT

TCP asusis-dsgn:3513 localhost:89 TIME_WAIT

TCP asusis-dsgn:3514 localhost:89 TIME_WAIT

TCP asusis-dsgn:3515 localhost:89 TIME_WAIT

TCP asusis-dsgn:3516 localhost:89 TIME_WAIT

TCP asusis-dsgn:3517 localhost:89 TIME_WAIT

TCP asusis-dsgn:3518 localhost:89 TIME_WAIT

TCP asusis-dsgn:3519 localhost :89 TIME_WAIT

TCP asusis-dsgn:3520 localhost:89 TIME_WAIT

TCP asusis-dsgn:3521 localhost:89 TIME_WAIT

TCP asusis- dsgn:3522 localhost:89 TIME_WAIT

TCP asusis-dsgn:3523 localhost:89 TIME_WAIT

TCP asusis-dsgn:3524 localhost:89 TIME_WAIT

TCP asusis-dsgn:3525 localhost:89 TIME_WAIT

TCP asusis-dsgn:3526 localhost:89 TIME_WAIT

TCP asusis-dsgn: 3527 localhost:89 TIME_WAIT


我认为由于某种原因,.net框架并没有真正关闭

套接字,因此它仍处于TIME_WAIT状态


经过数千次TIME_WAIT连接,操作系统拒绝连接。


Pleaseeeeee帮助解决它!!

谢谢

This is making me crazy!!

Please, if some body can help me.

I''m testing a ver simple socket client.
In my test I just open and close a connection (in a loop) to my local IIS
server (port 80)

using System.Net.Sockets;

for (int I = 0; I < 5000; I++)
{
TcpClient myClient = new TcpClient();
try
{
myClient.Connect("127.0.0.1", 80)
}
catch (Exception ex) {MessangeBox.Show(ex.ToString()); }
myClient.Close()
} //End for
Everything go fine, thousands of connections are opened and closed until
this error appear....

[ System.Net.Sockets.SocketException: Only one usage of each socket address
(protocol/network address/port) is normally permitted ]

After this error, I execute the netstat -a command and the lines (below)
appear thousands of times, lines below are just a very little part of the
complete list.

TCP asusis-dsgn:3505 localhost:80 TIME_WAIT
TCP asusis-dsgn:3506 localhost:80 TIME_WAIT
TCP asusis-dsgn:3507 localhost:89 TIME_WAIT
TCP asusis-dsgn:3508 localhost:89 TIME_WAIT
TCP asusis-dsgn:3509 localhost:89 TIME_WAIT
TCP asusis-dsgn:3510 localhost:89 TIME_WAIT
TCP asusis-dsgn:3511 localhost:89 TIME_WAIT
TCP asusis-dsgn:3512 localhost:89 TIME_WAIT
TCP asusis-dsgn:3513 localhost:89 TIME_WAIT
TCP asusis-dsgn:3514 localhost:89 TIME_WAIT
TCP asusis-dsgn:3515 localhost:89 TIME_WAIT
TCP asusis-dsgn:3516 localhost:89 TIME_WAIT
TCP asusis-dsgn:3517 localhost:89 TIME_WAIT
TCP asusis-dsgn:3518 localhost:89 TIME_WAIT
TCP asusis-dsgn:3519 localhost:89 TIME_WAIT
TCP asusis-dsgn:3520 localhost:89 TIME_WAIT
TCP asusis-dsgn:3521 localhost:89 TIME_WAIT
TCP asusis-dsgn:3522 localhost:89 TIME_WAIT
TCP asusis-dsgn:3523 localhost:89 TIME_WAIT
TCP asusis-dsgn:3524 localhost:89 TIME_WAIT
TCP asusis-dsgn:3525 localhost:89 TIME_WAIT
TCP asusis-dsgn:3526 localhost:89 TIME_WAIT
TCP asusis-dsgn:3527 localhost:89 TIME_WAIT

I think that for some reason the .net framework is not really closing the
socket, so it still alive with the TIME_WAIT status

And after thousands of TIME_WAIT connections, the OS reject connections.

Pleaseeeeee help to solve it!!
Thanks

推荐答案

AA,


我在一篇关于SQL服务器和连接到的文章中发现了以下内容

it:


请注意,SQL Server网络库特别没有为安全性启用

SO_REUSEADDR TCP / IP套接字选项原因。当启用SO_REUSEADDR

时,恶意用户可以将客户端端口劫持到SQL Server,并使用客户端提供的

凭据来获取对计算机的访问权限。 />
运行SQL Server。默认情况下,因为SQL Server网络库确实没有启用SO_REUSEADDR套接字选项,所以每次通过客户端上的SQL Server网络库打开和关闭

套接字时插座

进入TIME_WAIT状态四分钟。如果您正在快速打开并且在禁用池的情况下通过TCP / IP关闭SQL Server连接,则可以快速打开和关闭TCP / IP套接字。换句话说,每个SQL Server

连接都有一个TCP / IP套接字。如果您在不到四分钟的时间内快速打开并关闭4000个插槽

,您将达到

客户端匿名端口的默认最大设置,并且新的套接字连接尝试将失败,直到

现有的TIME_WAIT套接字超时。


虽然你没有使用SQL服务器,但你遇到同样的问题

。您可以做的是在注册表中设置以下值:

HKEY_LOCAL_MACHINE \SYSTEM\CurrentControlSet \ Servic es\Tcpip\Parameters\TcpTim

edWaitDelay


您可以将值设置为套接字

再次可用之前等待的秒数。

但是,设置此值可能会产生不利影响。是否需要打开几千个客户端连接?
?可以做一个不同的,并且更有效的方式吗?设置上述值是危险的,因为它是机器范围内的



希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- nick(dot)paldino = at = exisconsulting< dot> com


" ; AA" < aa@personal.net.py>在消息中写道

新闻:OU ************** @ TK2MSFTNGP11.phx.gbl ...
AA,

I found the following in an article about SQL server and connecting to
it:

Note that the SQL Server network library specifically does not enable the
SO_REUSEADDR TCP/IP socket option for security reasons. When SO_REUSEADDR is
enabled, a malicious user can hijack a client port to SQL Server and use the
credentials that the client supplies to gain access to the computer that is
running SQL Server. By default, because the SQL Server network library does
not enable the SO_REUSEADDR socket option, every time you open and close a
socket through the SQL Server network library on the client side, the socket
enters a TIME_WAIT state for four minutes. If you are rapidly opening and
closing SQL Server connections over TCP/IP with pooling disabled, you are
rapidly opening and closing TCP/IP sockets. In other words, each SQL Server
connection has one TCP/IP socket. If you rapidly open and close 4000 sockets
in less than four minutes, you will reach the default maximum setting for
client anonymous ports, and new socket connection attempts fail until the
existing set of TIME_WAIT sockets times out.

While you are not using SQL server, it is the same problem you are
having. What you can do is set the following value in the registry:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servic es\Tcpip\Parameters\TcpTim
edWaitDelay

You can set the value to the number of seconds to wait before the socket
is usable again.

However, setting this can have detrimental effects. Is there a need to
open a few thousand client connections? Can it be done a different, and
more efficient way? Setting the above value is dangerous because it is
machine-wide.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"AA" <aa@personal.net.py> wrote in message
news:OU**************@TK2MSFTNGP11.phx.gbl...
这让我发疯!!

请,如果有人可以帮助我。

我正在测试一个简单的套接字客户端。
在我的测试中我只是打开和关闭连接(在循环中)到我的本地IIS
服务器(端口80)

使用System.Net.Sockets;

for(int I = 0; I< 5000; I ++)
{/ t> TcpClient myClient = new TcpClient();
尝试
{my / i> myClient.Connect(" 127.0.0.1", 80)
}
catch(Exception ex){MessangeBox.Show(ex.ToString()); }
myClient.Close()
} //结束

一切顺利,数千个连接被打开和关闭,直到
出现此错误....

[System.Net.Sockets.SocketException:通常只允许使用每个套接字
地址(协议/网络地址/端口)]

之后错误,我执行netstat -a命令和行(下面)
出现数千次,下面的行只是
完整列表的一小部分。

TCP asusis-dsgn:3505 localhost:80 TIME_WAIT
TCP asusis-dsgn:3506 localhost:80 TIME_WAIT
TCP asusis-dsgn:3507 localhost:89 TIME_WAIT
TCP asusis-dsgn:3508 localhost:89 TIME_WAIT
TCP asusis-dsgn:3509 localhost:89 TIME_WAIT
TCP asusis-dsgn:3510 localhost:89 TIME_WAIT
TCP asusis-dsgn:3511 localhost:89 TIME_WAIT
TCP asusis-dsgn:3512 localhost:89 TIME_WAIT
TCP asusis-dsgn:3513 localhost:89 TIME_WAIT
TCP asusis-dsgn:3514 localhost:89 TIME_WAIT
TCP asusis- dsgn:3515 localhost:89 TIME_WAIT
TCP asusis-dsgn:3516 localhost:89 TIME_WAIT
TCP asusis-dsgn:3517 localhost:89 TIME_WAIT
TCP asusis-dsgn:3518 localhost:89 TIME_WAIT
TCP asusis-dsgn:3519 localhost:89 TIME_WAIT
TCP asusis-dsgn:3520 localhost:89 TIME_WAIT
TCP asusis-dsgn:3521 localhost:89 TIME_WAIT
TCP asusis-dsgn: 3522 localhost:89 TIME_WAIT
TCP asusis-dsgn:3523 localhost:89 TIME_WAIT
TCP asusis-dsgn:3524 localhost:89 TIME_WAIT
TCP asusis-dsgn:3525 localhost:89 T IME_WAIT
TCP asusis-dsgn:3526 localhost:89 TIME_WAIT
TCP asusis-dsgn:3527 localhost:89 TIME_WAIT

我认为由于某种原因,.net框架并不是真的关闭
套接字,所以它仍然处于TIME_WAIT状态

经过数千次TIME_WAIT连接,操作系统拒绝连接。

请帮助解决它! !

谢谢
This is making me crazy!!

Please, if some body can help me.

I''m testing a ver simple socket client.
In my test I just open and close a connection (in a loop) to my local IIS
server (port 80)

using System.Net.Sockets;

for (int I = 0; I < 5000; I++)
{
TcpClient myClient = new TcpClient();
try
{
myClient.Connect("127.0.0.1", 80)
}
catch (Exception ex) {MessangeBox.Show(ex.ToString()); }
myClient.Close()
} //End for
Everything go fine, thousands of connections are opened and closed until
this error appear....

[ System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted ]

After this error, I execute the netstat -a command and the lines (below)
appear thousands of times, lines below are just a very little part of the
complete list.

TCP asusis-dsgn:3505 localhost:80 TIME_WAIT
TCP asusis-dsgn:3506 localhost:80 TIME_WAIT
TCP asusis-dsgn:3507 localhost:89 TIME_WAIT
TCP asusis-dsgn:3508 localhost:89 TIME_WAIT
TCP asusis-dsgn:3509 localhost:89 TIME_WAIT
TCP asusis-dsgn:3510 localhost:89 TIME_WAIT
TCP asusis-dsgn:3511 localhost:89 TIME_WAIT
TCP asusis-dsgn:3512 localhost:89 TIME_WAIT
TCP asusis-dsgn:3513 localhost:89 TIME_WAIT
TCP asusis-dsgn:3514 localhost:89 TIME_WAIT
TCP asusis-dsgn:3515 localhost:89 TIME_WAIT
TCP asusis-dsgn:3516 localhost:89 TIME_WAIT
TCP asusis-dsgn:3517 localhost:89 TIME_WAIT
TCP asusis-dsgn:3518 localhost:89 TIME_WAIT
TCP asusis-dsgn:3519 localhost:89 TIME_WAIT
TCP asusis-dsgn:3520 localhost:89 TIME_WAIT
TCP asusis-dsgn:3521 localhost:89 TIME_WAIT
TCP asusis-dsgn:3522 localhost:89 TIME_WAIT
TCP asusis-dsgn:3523 localhost:89 TIME_WAIT
TCP asusis-dsgn:3524 localhost:89 TIME_WAIT
TCP asusis-dsgn:3525 localhost:89 TIME_WAIT
TCP asusis-dsgn:3526 localhost:89 TIME_WAIT
TCP asusis-dsgn:3527 localhost:89 TIME_WAIT

I think that for some reason the .net framework is not really closing the
socket, so it still alive with the TIME_WAIT status

And after thousands of TIME_WAIT connections, the OS reject connections.

Pleaseeeeee help to solve it!!
Thanks



优秀。


非常感谢你很多尼古拉斯,这就是我被搜索的解释。

很长一段时间。


AA

Nicholas Paldino [。 NET / C#MVP]" < NI ************** @ exisconsulting.com>在消息新闻中写了

:%2 **************** @ TK2MSFTNGP11.phx.gbl ...
Excellent.

Thank you very much Nicholas, this is the explain that I was searched for
long time.

AA
"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:%2****************@TK2MSFTNGP11.phx.gbl...
AA,

我在一篇关于SQL服务器并连接到它的文章中发现了以下内容:

请注意,SQL Server网络库特别没有启用
出于安全原因,SO_REUSEADDR TCP / IP套接字选项。启用S​​O_REUSEADDR
后,恶意用户可以将客户端端口劫持到SQL Server,并使用
客户端提供的凭据来访问
运行SQL Server的计算机。默认情况下,因为SQL Server网络库
没有启用SO_REUSEADDR套接字选项,所以每次通过客户端的SQL Server网络库打开和关闭
套接字时,
套接字进入TIME_WAIT状态四分钟。如果您在禁用池的情况下快速打开并通过TCP / IP关闭SQL Server连接,则可以快速打开和关闭TCP / IP套接字。换句话说,每个SQL
服务器连接都有一个TCP / IP套接字。如果您在不到四分钟的时间内快速打开并关闭4000
套接字,您将达到
客户端匿名端口的默认最大设置,并且新的套接字连接尝试将失败,直到
现有的TIME_WAIT集合套接字超时。

虽然你没有使用SQL服务器,但是你遇到了同样的问题。您可以做的是在注册表中设置以下值:

您可以将值设置为
套接字再次可用之前等待的秒数。

然而,设置此值可能会产生不利影响。是否需要
来打开几千个客户端连接?可以做一个不同的,更有效的方式吗?设置上述值是危险的,因为它在机器范围内。

希望这会有所帮助。

-
- Nicholas Paldino [.NET / C#MVP]
- nick(dot)paldino = at = exisconsulting< dot> com

" AA" < aa@personal.net.py>在消息中写道
新闻:OU ************** @ TK2MSFTNGP11.phx.gbl ...
AA,

I found the following in an article about SQL server and connecting to
it:

Note that the SQL Server network library specifically does not enable the
SO_REUSEADDR TCP/IP socket option for security reasons. When SO_REUSEADDR is enabled, a malicious user can hijack a client port to SQL Server and use the credentials that the client supplies to gain access to the computer that is running SQL Server. By default, because the SQL Server network library does not enable the SO_REUSEADDR socket option, every time you open and close a
socket through the SQL Server network library on the client side, the socket enters a TIME_WAIT state for four minutes. If you are rapidly opening and
closing SQL Server connections over TCP/IP with pooling disabled, you are
rapidly opening and closing TCP/IP sockets. In other words, each SQL Server connection has one TCP/IP socket. If you rapidly open and close 4000 sockets in less than four minutes, you will reach the default maximum setting for
client anonymous ports, and new socket connection attempts fail until the
existing set of TIME_WAIT sockets times out.

While you are not using SQL server, it is the same problem you are
having. What you can do is set the following value in the registry:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servic es\Tcpip\Parameters\TcpTim edWaitDelay

You can set the value to the number of seconds to wait before the socket is usable again.

However, setting this can have detrimental effects. Is there a need to open a few thousand client connections? Can it be done a different, and
more efficient way? Setting the above value is dangerous because it is
machine-wide.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"AA" <aa@personal.net.py> wrote in message
news:OU**************@TK2MSFTNGP11.phx.gbl...
这让我疯了!!

请,如果有人可以帮助我。

我正在测试一个简单的套接字客户端。
在我的测试中我只是打开和关闭一个连接(在一个循环)到我的本地
IIS服务器(端口80)

使用System.Net.Sockets;

for(int I = 0; I< 5000 ; I ++)
{/ t> TcpClient myClient = new TcpClient();
尝试
{my / i> myClient.Connect(" 127.0.0.1",80)
}
catch(Exception ex){MessangeBox.Show(ex.ToString()); }
myClient.Close()
} //结束

一切顺利,数千个连接被打开和关闭,直到
出现此错误....

[System.Net.Sockets.SocketException:每个套接字只有一种用法
This is making me crazy!!

Please, if some body can help me.

I''m testing a ver simple socket client.
In my test I just open and close a connection (in a loop) to my local IIS server (port 80)

using System.Net.Sockets;

for (int I = 0; I < 5000; I++)
{
TcpClient myClient = new TcpClient();
try
{
myClient.Connect("127.0.0.1", 80)
}
catch (Exception ex) {MessangeBox.Show(ex.ToString()); }
myClient.Close()
} //End for
Everything go fine, thousands of connections are opened and closed until
this error appear....

[ System.Net.Sockets.SocketException: Only one usage of each socket


地址

(协议/网络地址/端口)通常是允许]

在这个错误之后,我执行netstat -a命令并且行(下面)
出现了数千次,下面的行只是
的一小部分TCP asusis-dsgn:3505 localhost:80 TIME_WAIT
TCP asusis-dsgn:3506 localhost:80 TIME_WAIT
TCP asusis-dsgn:3507 localhost:89 TIME_WAIT
TCP asusis-dsgn:3508 localhost:89 TIME_WAIT
TCP asusis-dsgn:3509 localhost:89 TIME_WAIT
TCP asusis-dsgn:3510 localhost:89 TIME_WAIT
TCP asusis-dsgn:3511 localhost:89 TIME_WAIT
TCP asusis-dsgn:3512 localhost:89 TIME_WAIT
TCP asusis-dsgn:3513 localhost:89 TIME_WAIT
TCP asusis-dsgn:3514 localhost:89 TIME_WAIT
TCP asusis-dsgn:3515 localhost:89 TIME_WAIT
TCP asusis-dsgn:3516 localhost:89 TIME_WAIT
TCP asusis-dsgn:3517 localhost:89 TIME_WAIT
TCP asusis- dsgn:3518 localhost:89 TIME_WAIT
TCP asusis-dsgn:3519 localhost:89 TIME_WAIT
TCP asusis-dsgn:3520 localhost:89 TIME_WAIT
TCP asusis-dsgn:3521 localhost:89 TIME_WAIT
TCP asusis-dsgn:3522 localhost:89 TIME_WAIT
TCP asusis-dsgn:3523 localhost:89 TIME_WAIT
TCP asusis-dsgn:3524 localhost:89 TIME_WAIT
TCP as usis-dsgn:3525 localhost:89 TIME_WAIT
TCP asusis-dsgn:3526 localhost:89 TIME_WAIT
TCP asusis-dsgn:3527 localhost:89 TIME_WAIT

我认为对于某些人来说因为.net框架没有真正关闭
套接字,所以它仍然处于TIME_WAIT状态

经过数千次TIME_WAIT连接后,操作系统拒绝
连接。 /> Pleaseeeeee帮忙解决它!!

谢谢
(protocol/network address/port) is normally permitted ]

After this error, I execute the netstat -a command and the lines (below)
appear thousands of times, lines below are just a very little part of the complete list.

TCP asusis-dsgn:3505 localhost:80 TIME_WAIT
TCP asusis-dsgn:3506 localhost:80 TIME_WAIT
TCP asusis-dsgn:3507 localhost:89 TIME_WAIT
TCP asusis-dsgn:3508 localhost:89 TIME_WAIT
TCP asusis-dsgn:3509 localhost:89 TIME_WAIT
TCP asusis-dsgn:3510 localhost:89 TIME_WAIT
TCP asusis-dsgn:3511 localhost:89 TIME_WAIT
TCP asusis-dsgn:3512 localhost:89 TIME_WAIT
TCP asusis-dsgn:3513 localhost:89 TIME_WAIT
TCP asusis-dsgn:3514 localhost:89 TIME_WAIT
TCP asusis-dsgn:3515 localhost:89 TIME_WAIT
TCP asusis-dsgn:3516 localhost:89 TIME_WAIT
TCP asusis-dsgn:3517 localhost:89 TIME_WAIT
TCP asusis-dsgn:3518 localhost:89 TIME_WAIT
TCP asusis-dsgn:3519 localhost:89 TIME_WAIT
TCP asusis-dsgn:3520 localhost:89 TIME_WAIT
TCP asusis-dsgn:3521 localhost:89 TIME_WAIT
TCP asusis-dsgn:3522 localhost:89 TIME_WAIT
TCP asusis-dsgn:3523 localhost:89 TIME_WAIT
TCP asusis-dsgn:3524 localhost:89 TIME_WAIT
TCP asusis-dsgn:3525 localhost:89 TIME_WAIT
TCP asusis-dsgn:3526 localhost:89 TIME_WAIT
TCP asusis-dsgn:3527 localhost:89 TIME_WAIT

I think that for some reason the .net framework is not really closing the socket, so it still alive with the TIME_WAIT status

And after thousands of TIME_WAIT connections, the OS reject connections.
Pleaseeeeee help to solve it!!
Thanks




另一个问题..有可能,以编程方式(在.NET中)设置这个

属性吗?不适用于所有应用程序,对于我想要的特定应用程序?


因为,当我使用Microsoft Application Center测试时,我认为他打开了b
关闭成千上万的连接,但当我执行netstat时,我看到

只有1条记录


这对我来说非常好


非常感谢


AA

Nicholas Paldino [.NET / C#MVP]" < NI ************** @ exisconsulting.com>在消息新闻中写了

:%2 **************** @ TK2MSFTNGP11.phx.gbl ...
Another question.. Is possible that, programatically (in .NET) to set this
property? Not for all applications, for a specific application that I want?

Because, When I use the Microsoft Application Center Test, I look that he
open and close thousands of connection, but when i execute the netstat I saw
just 1 record

It will be excellent for me

Thanks a lot

AA
"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:%2****************@TK2MSFTNGP11.phx.gbl...
AA,

我在一篇关于SQL服务器并连接到它的文章中发现了以下内容:

请注意,SQL Server网络库特别没有启用
出于安全原因,SO_REUSEADDR TCP / IP套接字选项。启用S​​O_REUSEADDR
后,恶意用户可以将客户端端口劫持到SQL Server,并使用
客户端提供的凭据来访问
运行SQL Server的计算机。默认情况下,因为SQL Server网络库
没有启用SO_REUSEADDR套接字选项,所以每次通过客户端的SQL Server网络库打开和关闭
套接字时,
套接字进入TIME_WAIT状态四分钟。如果您在禁用池的情况下快速打开并通过TCP / IP关闭SQL Server连接,则可以快速打开和关闭TCP / IP套接字。换句话说,每个SQL
服务器连接都有一个TCP / IP套接字。如果您在不到四分钟的时间内快速打开并关闭4000
套接字,您将达到
客户端匿名端口的默认最大设置,并且新的套接字连接尝试将失败,直到
现有的TIME_WAIT集合套接字超时。

虽然你没有使用SQL服务器,但是你遇到了同样的问题。您可以做的是在注册表中设置以下值:

您可以将值设置为
套接字再次可用之前等待的秒数。

然而,设置此值可能会产生不利影响。是否需要
来打开几千个客户端连接?可以做一个不同的,更有效的方式吗?设置上述值是危险的,因为它在机器范围内。

希望这会有所帮助。

-
- Nicholas Paldino [.NET / C#MVP]
- nick(dot)paldino = at = exisconsulting< dot> com

" AA" < aa@personal.net.py>在消息中写道
新闻:OU ************** @ TK2MSFTNGP11.phx.gbl ...
AA,

I found the following in an article about SQL server and connecting to
it:

Note that the SQL Server network library specifically does not enable the
SO_REUSEADDR TCP/IP socket option for security reasons. When SO_REUSEADDR is enabled, a malicious user can hijack a client port to SQL Server and use the credentials that the client supplies to gain access to the computer that is running SQL Server. By default, because the SQL Server network library does not enable the SO_REUSEADDR socket option, every time you open and close a
socket through the SQL Server network library on the client side, the socket enters a TIME_WAIT state for four minutes. If you are rapidly opening and
closing SQL Server connections over TCP/IP with pooling disabled, you are
rapidly opening and closing TCP/IP sockets. In other words, each SQL Server connection has one TCP/IP socket. If you rapidly open and close 4000 sockets in less than four minutes, you will reach the default maximum setting for
client anonymous ports, and new socket connection attempts fail until the
existing set of TIME_WAIT sockets times out.

While you are not using SQL server, it is the same problem you are
having. What you can do is set the following value in the registry:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servic es\Tcpip\Parameters\TcpTim edWaitDelay

You can set the value to the number of seconds to wait before the socket is usable again.

However, setting this can have detrimental effects. Is there a need to open a few thousand client connections? Can it be done a different, and
more efficient way? Setting the above value is dangerous because it is
machine-wide.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"AA" <aa@personal.net.py> wrote in message
news:OU**************@TK2MSFTNGP11.phx.gbl...
这让我疯了!!

请,如果有人可以帮助我。

我正在测试一个简单的套接字客户端。
在我的测试中我只是打开和关闭一个连接(在一个循环)到我的本地
IIS服务器(端口80)

使用System.Net.Sockets;

for(int I = 0; I< 5000 ; I ++)
{/ t> TcpClient myClient = new TcpClient();
尝试
{my / i> myClient.Connect(" 127.0.0.1",80)
}
catch(Exception ex){MessangeBox.Show(ex.ToString()); }
myClient.Close()
} //结束

一切顺利,数千个连接被打开和关闭,直到
出现此错误....

[System.Net.Sockets.SocketException:每个套接字只有一种用法
This is making me crazy!!

Please, if some body can help me.

I''m testing a ver simple socket client.
In my test I just open and close a connection (in a loop) to my local IIS server (port 80)

using System.Net.Sockets;

for (int I = 0; I < 5000; I++)
{
TcpClient myClient = new TcpClient();
try
{
myClient.Connect("127.0.0.1", 80)
}
catch (Exception ex) {MessangeBox.Show(ex.ToString()); }
myClient.Close()
} //End for
Everything go fine, thousands of connections are opened and closed until
this error appear....

[ System.Net.Sockets.SocketException: Only one usage of each socket


地址

(协议/网络地址/端口)通常是允许]

在这个错误之后,我执行netstat -a命令并且行(下面)
出现了数千次,下面的行只是
的一小部分TCP asusis-dsgn:3505 localhost:80 TIME_WAIT
TCP asusis-dsgn:3506 localhost:80 TIME_WAIT
TCP asusis-dsgn:3507 localhost:89 TIME_WAIT
TCP asusis-dsgn:3508 localhost:89 TIME_WAIT
TCP asusis-dsgn:3509 localhost:89 TIME_WAIT
TCP asusis-dsgn:3510 localhost:89 TIME_WAIT
TCP asusis-dsgn:3511 localhost:89 TIME_WAIT
TCP asusis-dsgn:3512 localhost:89 TIME_WAIT
TCP asusis-dsgn:3513 localhost:89 TIME_WAIT
TCP asusis-dsgn:3514 localhost:89 TIME_WAIT
TCP asusis-dsgn:3515 localhost:89 TIME_WAIT
TCP asusis-dsgn:3516 localhost:89 TIME_WAIT
TCP asusis-dsgn:3517 localhost:89 TIME_WAIT
TCP asusis- dsgn:3518 localhost:89 TIME_WAIT
TCP asusis-dsgn:3519 localhost:89 TIME_WAIT
TCP asusis-dsgn:3520 localhost:89 TIME_WAIT
TCP asusis-dsgn:3521 localhost:89 TIME_WAIT
TCP asusis-dsgn:3522 localhost:89 TIME_WAIT
TCP asusis-dsgn:3523 localhost:89 TIME_WAIT
TCP asusis-dsgn:3524 localhost:89 TIME_WAIT
TCP as usis-dsgn:3525 localhost:89 TIME_WAIT
TCP asusis-dsgn:3526 localhost:89 TIME_WAIT
TCP asusis-dsgn:3527 localhost:89 TIME_WAIT

我认为对于某些人来说因为.net框架没有真正关闭
套接字,所以它仍然处于TIME_WAIT状态

经过数千次TIME_WAIT连接后,操作系统拒绝
连接。 /> Pleaseeeeee帮忙解决它!!

谢谢
(protocol/network address/port) is normally permitted ]

After this error, I execute the netstat -a command and the lines (below)
appear thousands of times, lines below are just a very little part of the complete list.

TCP asusis-dsgn:3505 localhost:80 TIME_WAIT
TCP asusis-dsgn:3506 localhost:80 TIME_WAIT
TCP asusis-dsgn:3507 localhost:89 TIME_WAIT
TCP asusis-dsgn:3508 localhost:89 TIME_WAIT
TCP asusis-dsgn:3509 localhost:89 TIME_WAIT
TCP asusis-dsgn:3510 localhost:89 TIME_WAIT
TCP asusis-dsgn:3511 localhost:89 TIME_WAIT
TCP asusis-dsgn:3512 localhost:89 TIME_WAIT
TCP asusis-dsgn:3513 localhost:89 TIME_WAIT
TCP asusis-dsgn:3514 localhost:89 TIME_WAIT
TCP asusis-dsgn:3515 localhost:89 TIME_WAIT
TCP asusis-dsgn:3516 localhost:89 TIME_WAIT
TCP asusis-dsgn:3517 localhost:89 TIME_WAIT
TCP asusis-dsgn:3518 localhost:89 TIME_WAIT
TCP asusis-dsgn:3519 localhost:89 TIME_WAIT
TCP asusis-dsgn:3520 localhost:89 TIME_WAIT
TCP asusis-dsgn:3521 localhost:89 TIME_WAIT
TCP asusis-dsgn:3522 localhost:89 TIME_WAIT
TCP asusis-dsgn:3523 localhost:89 TIME_WAIT
TCP asusis-dsgn:3524 localhost:89 TIME_WAIT
TCP asusis-dsgn:3525 localhost:89 TIME_WAIT
TCP asusis-dsgn:3526 localhost:89 TIME_WAIT
TCP asusis-dsgn:3527 localhost:89 TIME_WAIT

I think that for some reason the .net framework is not really closing the socket, so it still alive with the TIME_WAIT status

And after thousands of TIME_WAIT connections, the OS reject connections.
Pleaseeeeee help to solve it!!
Thanks




这篇关于插座不要真的关闭。请帮助微软MVP!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆