The total number of sockets that can be created using the SocketTools controls or libraries varies, based on the version of Windows and the amount of physical memory that is available. It is also important to distinguish between the number of sockets that can be allocated by a client application and the number of inbound connections a server can accept.
More Information
By default, client applications will be automatically assigned local port numbers between 1024 and 5000 when a connection is made. These local ports are called ephemeral ports because they are temporary ports allocated automatically as part of the process of establishing the connection. This means that if one or more clients establish a large number of connections, or rapidly connect and disconnect from a server, all of the ephemeral ports in that range may be allocated. This creates a practical limit of 3976 client connections system-wide, either active or in the time-wait state. It is possible to increase the number of ephemeral ports available using the RegEdit.exe utility to select the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
Create or modify a DWORD value called MaxUserPort, and specify the maximum port number that you wish to use. Valid values range from 5000 to 65534, with a default value of 5000. As with any change to the registry, it is recommended that you have a current backup and system restore point prior to making modifications so that you can revert the changes if necessary.
Server applications that accept incoming connections must allocate a socket for each connection, with each socket allocated from the non-paged memory pool. The actual number of sockets that can be created system-wide depends on the amount of physical memory that is installed. The non-paged memory pool is 1/8th the size of physical RAM, with a maximum of 256M. The theoretical maximum for Windows is approximately 25,000 socket handles; however, in practical terms, it is safe to estimate that the Windows Server platforms can allocate approximately 16,000 handles on a system with 2G or more of RAM.
It is also important to remember that the maximum number of socket handles that can be created is not the same as the maximum number of active client sessions a server can support. Typically, client sessions are managed by multiple threads, with each thread being allocated it's own stack, along with memory and other resources used by the server to satisfy the requests made by the client. A lightweight server that does minimal processing would be able to handle many more client connections than one which performs extensive disk I/O or performs more compute-intensive tasks, regardless of the actual number of socket handles allocated.
See Also
SocketTools and Multi-threading
Unable to Connect from TCP Ports Above 5000