What limits the number of connections for a TCP port?

Suppose I have an application that will listen on a specific TCP port for connection. Is there a theoretical limit to the number of connections that can be processed on the same port?

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

I searched the Internet but could not find a definitive answer.

thanks

+4
source share
2 answers

If the process limit (as shown by the ulimit command) is 1024, and you did not close STDIN, STDOUT and STDERR, and 100 file descriptors are used by elements such as database connections and other files, then you will have 921 available for simultaneous processing. This assumes that all connections are processed in parallel. These file descriptors will be reused after each connection is closed. The end result is that if your application correctly handles file descriptors, the total number of connections between starting and shutting down the application is infinite.

+5
source

On UNIX (not Windows), the accepted socket uses a file descriptor, so the limit is the number of open file descriptors allowed. The number of open file descriptors is the limit for each process with a hard and soft limit. See ulimit (2) for more information.

Note that if you close the socket, you will release the file descriptor so that it can be used again. The ulimit limit applies only to the number of simultaneous open file descriptors.

To specifically answer your question, there is no limit on the number of sockets a port can accept, only on the number that the process that is listening on the port can be opened at the same time. If there was a limit, web servers that listen on port 80 would need to be restarted more often.

+2
source

All Articles