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

前端 未结 3 2060
礼貌的吻别
礼貌的吻别 2020-12-10 22:13

I\'m building a chat server with .NET. I have tried opening about 2000 client connections and my Linksys WRT54GL router (with tomato firmware) drops dead each time. The same

相关标签:
3条回答
  • 2020-12-10 22:29

    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. but this is configurable via a registry tweak to change the MaxUSerPort setting from 5000 to say, 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. that way, you can scale your system to handle n x 64k ports.

    0 讨论(0)
  • 2020-12-10 22:34

    Had for days a problem with the available sockets on my Window 7 machine. After reading some articles about socket leaks in Win 7, I applied a Windows patch - nothing changed.

    Below there is an article describing windows connection problems in great detail: http://technet.microsoft.com/en-us/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); EnableConnectionRateLimiting, REG_DWORD, value 0;
      • HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip: Create MaxUserPort, REG_DWORD, decimal value 65534
    2. Restart Windows
    0 讨论(0)
  • 2020-12-10 22:35

    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. The IP protocol only allows for a maximum of 65535 ports and many of these are reserved and not available for general use. 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. The server creates a new chat session and responds with the session 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.

    0 讨论(0)
提交回复
热议问题