Max Outgoing Socket Connections in .NET/Windows Server Max Outgoing Socket Connections in .NET/Windows Server windows windows

Max Outgoing Socket Connections in .NET/Windows Server


A Windows machine can easily scale to very high numbers of open connections. The 64k ephemeral port limit is per IP address, not per machine. If you need more ephemeral ports, increase the limits as @SuperTux suggests, but also assign more IPs to the machine. To take advantage, you'll have to manually call Bind() on your client socket and pass a source IP from your pool with free ports (this also implies you'll be responsible for keeping track of available ephemeral port counts per address). Lots of high-end appliance- type devices do this (SNAT pools on load balancers, for instance) to support hundreds of thousands of concurrent connections.

Bookkeeping is a hassle, but better than throwing underutilized hardware at it for every 64k client connections.


65355 is a limit of the IP protocol and more importantly is the limit the TCP/IP stacks of most operating systems impose.

To increase the maximum number of ephemeral ports on Windows, follow these steps:

  1. Start Registry Editor.
  2. Locate the following subkey in the registry, and then click Parameters:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
  3. On the Edit menu, click New, and then add the following registry entry:

    Value Name: MaxUserPort

    Value Type: DWORD

    Value data: 65534

    Valid Range: 5000-65534 (decimal)

    Default: 0x1388 (5000 decimal)

    Description: This parameter controls the maximum port number that is used when a program requests any available user port from the system. Typically , ephemeral (short-lived) ports are allocated between the values of 1024 and 5000 inclusive.

Normally to scale to more than 65K ports you would use multiple servers in a cluster.