Sockets – What limits the number of connections for a TCP port

socketstcp

Lets say I have an application that is going to listen on a particular TCP port for a connection. Is there a theoretical limit on the number of connections that can be handled in the same port?

Or is there only a practical limit based on the OS and other properties?

I've searched the Internet but couldn't find a conclusive answer.

Thanks

Best Answer

If the process limit (as shown by the ulimit command) is 1024, and you have not closed STDIN, STDOUT and STDERR and 100 file descriptors are used by items such as database connections and other file handles, than you will have 921 open connections available for simultaneous processing. This assumes that all connections are processed in parallel. These file descriptors will be reused once each connection is closed. The net result is that if your application handles the file descriptors correctly, the total number of connections between the start up and shutdown of the application, is infinite.