While writing a Java program, I noticed that a SINGLE TCP PORT (ServerSocket) can connect to MANY Connections (Sockets). Does this mean that a Single TCP PORT can THEORETICALLY handle infinite connections?

  • Did any answer help you? if so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you could provide and accept your own answer.
    – Ron Maupin
    Aug 12 '17 at 3:25

The TCP tuple is composed of:

  • source IP
  • source port
  • destination IP
  • destination port

Since your sever socket is listening to one port and I presume one IP address (although it could be more) the remaining factors are the IP address and port on the remote end, i.e. the client.

For IPv4 there are 2^32 addresses, out of which roughly 3.5 billion are usable. There are 2^16 ports, most of which won't be used by clients as most TCP stacks use only a high range but let's say we are dealing with a client that could use any port, so that gives you a potential number of connections around 3.5*65000 = 229*10^12. That's more than you could ever hope to realistically handle on a single server.


There only exist 65536 ports (from 0 to 65535), one of then located by the IANA into well known ports(lower to 1024), registered ports(from 1024 to 49151, that can be used by any application) and private or dynamic ports (from 49152 to 65535 assigned dynamically to a cliento who iniciates the connection). If you, THEORETICALLY, will be a lot of CPU and RAM on your equipment, from one port, you only will be able to entablish 65536 sockets.

  • 1
    Would not be (From 1 to 65535) ?
    – TMoraes
    Oct 27 '15 at 13:17
  • 1
    Ok, you are rigth, port 0 is reserved, but it is permitted like source port as long as the source do not expect messages like response, i´m guessing, eg: UDP Oct 27 '15 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.