简体   繁体   English

我在Windows Server 2003中可以打开的套接字数量的上限是多少

[英]What is the upper limit on the number of open sockets I can have in Windows Server 2003

I'm building a chat server with .NET. 我正在用.NET构建聊天服务器。 I have tried opening about 2000 client connections and my Linksys WRT54GL router (with tomato firmware) drops dead each time. 我尝试打开大约2000个客户端连接,而我的Linksys WRT54GL路由器(带有番茄固件)每次都掉线。 The same thing happens when I have several connections open on my Azureus bit-torrent client. 当我在Azureus比特流客户端上打开多个连接时,也会发生同样的事情。

I have three questions: 我有三个问题:

  1. Is there a limit on the number of open sockets I can have in Windows Server 2003? 我可以在Windows Server 2003中打开套接字的数量有限制吗?
  2. Is the Linksys router the problem? Linksys路由器有问题吗? If so is there better hardware recommended? 如果可以,建议使用更好的硬件吗?
  3. Is there a way to possibly share sockets so that I can handle more open client connections with fewer resources? 有没有办法共享套接字,以便我可以用更少的资源处理更多的开放客户端连接?

AS I've mentioned before, Raymond Chen has good advice on this sort of question: If you have to ask about OS limits, you're probably doing something wrong. 正如我之前提到的, Raymond Chen在这种问题上有很好的建议:如果您不得不询问操作系统限制,那么您可能做错了什么。 The IP protocol only allows for a maximum of 65535 ports and many of these are reserved and not available for general use. IP协议最多只允许65535个端口,其中许多端口是保留的,不能用于一般用途。 I would suggest that your messaging protocols need to be thought out in more detail so that OS limits are not an issue. 我建议您需要更详细地考虑您的消息传递协议,以便操作系统限制不成问题。 I'm sure there are many good resources describing such systems, and there are certainly people here that would have good ideas about it. 我敢肯定,有很多很好的资源来描述这样的系统,并且肯定有人在这里有关于它的好主意。

EDIT: I'm going to put some thoughts about implementing a scalable chat server. 编辑:我将对实现可扩展的聊天服务器进行一些思考。

First off, designate a single port on the server for clients to communicate through. 首先,在服务器上指定一个端口以供客户端进行通信。 Whenever a client needs to update the chat state (a new user message for example) do the following: 每当客户端需要更新聊天状态(例如,新的用户消息)时,请执行以下操作:

create message packet
open port to server
send packet
close port

The server then does the following: 然后,服务器执行以下操作:

connection request received
get packet
close connection
process packet
for each client that requires updating
  open connection to clients
  send update packet
  close connection

When a new chat session is started, the client starting the session sends a 'new session' message to the server with the clients user details and IP address for responses. 当开始新的聊天会话时,启动会话的客户端会向服务器发送“新会话”消息,其中包含客户端用户详细信息和IP地址以进行响应。 The server creates a new chat session and responds with the session ID. 服务器创建一个新的聊天会话,并使用会话ID进行响应。 The client then sends packets containing the messages the user types, the server processes them and forwards the message to other clients in the same session. 然后,客户端发送包含用户键入的消息的数据包,服务器对它们进行处理,并将消息转发给同一会话中的其他客户端。 When a client leaves the chat, it sends a 'end session' message to the server. 当客户端离开聊天室时,它将向服务器发送“结束会话”消息。 The server removes the client from the session and destroys the session when there are no more clients in the session. 当会话中没有更多客户端时,服务器将从会话中删除客户端并销毁会话。

Hope that gets you thinking. 希望能让您思考。

我在为Windows XP搜索类似内容时发现了这个( http://smallvoid.com/article/winnt-tcpip-max-limit.html ),我认为这应该适用于Windows 2003

i have found some answers to this that i feel i should share: 我找到了一些我应该分享的答案:

Windows 2003 server has a limit on the number of ports that may be used. Windows 2003 Server对可以使用的端口数有限制。 but this is configurable via a registry tweak to change the MaxUSerPort setting from 5000 to say, 64k( max). 但这可以通过注册表调整进行配置,以将MaxUSerPort设置从5000更改为64k(max)。

Exploring further, i realize that the 64k port restriction is actually per IP address, hence a single server can easily attain much more ports, and hence TCP connections by either installing multiple network cards, or binding more than one IP address to a network card. 进一步探讨,我意识到64k端口限制实际上是针对每个IP地址的,因此一台服务器可以轻松地获得更多的端口,从而通过安装多个网卡或将一个以上IP地址绑定到一个网卡来实现TCP连接。 that way, you can scale your system to handle nx 64k ports. 这样,您可以扩展系统以处理nx 64k端口。

Had for days a problem with the available sockets on my Window 7 machine. 几天来,我的Window 7机器上的可用插槽出现了问题。 After reading some articles about socket leaks in Win 7, I applied a Windows patch - nothing changed. 在阅读了有关Win 7中套接字泄漏的一些文章之后,我应用了Windows补丁 -一切都没有改变。

Below there is an article describing windows connection problems in great detail: http://technet.microsoft.com/en-us/magazine/2007.12.network.aspx 下面是一篇详细描述Windows连接问题的文章: http : //technet.microsoft.com/zh-cn/magazine/2007.12.network.aspx

For me it worked the following: 对我来说,它的工作如下:

  1. Open Regedit 打开注册表编辑器
    • HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters: Create TcpNumConnections, REG_DWORD, decimal value 500 (this can be set according to your needs); HKEY_LOCAL_MACHINE \\ SYSTEM \\ CurrentControlSet \\ services \\ Tcpip \\ Parameters:创建TcpNumConnections,REG_DWORD,十进制值500(可以根据需要设置); EnableConnectionRateLimiting, REG_DWORD, value 0; EnableConnectionRateLimiting,REG_DWORD,值0;
    • HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\Tcpip: Create MaxUserPort, REG_DWORD, decimal value 65534 HKEY_LOCAL_MACHINE \\ SYSTEM \\ CurrentControlSet \\ services \\ Tcpip:创建MaxUserPort,REG_DWORD,十进制值65534
  2. Restart Windows 重新启动Windows

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

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