简体   繁体   English

Winsock是否限制并发连接数?

[英]Does Winsock limit the number of concurrent connections?

I've recently made a program in C# (stress tester), which creates an array of 100,000 sockets, and connects each of them to a specified server. 我最近用C#(压力测试仪)制作了一个程序,该程序创建了100,000个套接字的数组,并将每个套接字连接到指定的服务器。

Every time I have tested this, the program stopped at 16,334 sockets. 每次测试时,该程序都会在16,334个套接字处停止。 The last connected socket was socket 16,334. 最后连接的套接字是套接字16,334。 They all stayed connected until I closed them, but still I couldn't connect more than 16,334 sockets to the same server. 在关闭它们之前,它们一直保持连接状态,但是仍然无法将超过16,334个套接字连接到同一服务器。

Why does it happen? 为什么会发生? Is it a limitation of Winsock? 它是Winsock的局限性吗?

If so, can it somehow be bypassed? 如果是这样,可以以某种方式绕过它吗?

There are limits on the number of outbound connections that you can make and knowing exactly what you mean by "stopped at" would likely help determine your problem. 可以建立的出站连接数有限制,并且确切了解“停止于”的含义很可能有助于确定问题。 Which API is returning which error code causing you to "stop"? 哪个API返回哪个错误代码导致您“停止”?

The limits tend to be related to availability of ephemeral ports (see MaxUserPort ) and available memory and/or non-paged pool (though the later is rarely an issue on Vista or later). 限制通常与临时端口的可用性(请参阅MaxUserPort )以及可用内存和/或非页面缓冲的池有关(尽管后者在Vista或更高版本上很少会成为问题)。

You might trying running netstat when your process "stops" as this will show how many other processes also have connections established and are using ephemeral ports. 您可以尝试在进程“停止”时运行netstat,因为这将显示还有多少其他进程也已建立连接并且正在使用临时端口。

You could also take a look here , as depending on the OS that you're running on some of the information may be of use to you. 您也可以在这里查看一下 ,因为根据所运行的操作系统,某些信息可能对您有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM