5

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

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

5 Comments

i am more interested in windows.
In windows, the same principals apply but the max limit is actually dependent on the number of system resources available. Sockets on Windows are handles, which are a shared system resource.
ok thanks so in theory there is no such limit but practically there could be
@viswanathsan: FYI, I have supported a socket based application that was limited to 200 socket connections, processed up to 5 connections per second, about 100,000 connections each day and had at one point an uptime of about 500 days. (The server was rebooted because of a daylight saving time change.)
infinite is a very bad word in a computer world. Everything is finite here
3

In UNIX (Not Windows), an accepted socket consumes a file descriptor, so the limit is the number of open file descriptors allowed. The number of open file descriptors is a per-process limit with both a hard and a soft limit. See ulimit (2) for more information.

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

To specifically answer your question, there isn't a limit on the number of sockets a port can accept, only on the number that the process listening to the port can have open at the same time. If there were a limit, web servers, who listen on port 80, would have to be restarted more often.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.