How many sockets can be created from a port?
Asked
Active
Viewed 2.0k times
13
-
ou should probably look through http://stackoverflow.com/questions/651665/how-many-socket-connections-possible – jonny Mar 31 '09 at 08:42
-
Use of the term "listen" is ambiguous, in general one listens on a port not a socket. Is the quesion, "How many ports can a program listen to?" or "How many sockets can be created from a port (or set of ports)?" – AnthonyWJones Mar 31 '09 at 08:49
3 Answers
6
This is an operating system limit.
Basically each socket will require a file descriptor (in Linux/Unix terms; it's probably equivalent in Windows). The OS will have a per-process file descriptor limit (say 250-1000) and that'll be the upper limit.

cletus
- 616,129
- 168
- 910
- 942
-
1Not neccessarily. The listening thread can delegate the connection handling to another thread and close the file descriptor right away. So its rather maximum number threads times maximum number of file descriptors per thread. – wnrph Nov 16 '14 at 08:36
-
@artistoex which OS has a limit of file descriptors per _thread_ instead of per _process_? – tzot Sep 28 '17 at 07:23
-
@tzot Under Linux threads basically _are_ processes. Have a look at [clone(2)](https://linux.die.net/man/2/clone) As far as I understand it, it allows you to create threads which do not share file descriptors. – wnrph Sep 30 '17 at 10:57
-
@artistoex in the same spirit, read [pthread(7)](https://linux.die.net/man/7/pthreads) for a definition of threads in posix. Then it becomes obvious that clone(2) and process-as-a-thread is an _implementation detail_ of the Linux kernel and the universally applicable formula is: maximum number of _processes_ times maximum number of FDs per _process_. – tzot Oct 01 '17 at 22:00
2
That'll be governed by the number of client-side ports available to your process (that i, when you open a connection to a remote host/port combination, you will also require a port at your end).
The total of client side (or ephemeral) ports will be made available to all the processes on your machine. So it depends on what else is currently running.
The number of ports and the configuration is OS dependent. Just Google for 'max number of ports' plus your OS.

Brian Agnew
- 268,207
- 37
- 334
- 440