8

If the client joins to a server, then there is a local port, and a remote port in each connection. What happens, if more than 65535 client tries to join to my server?

  • 1
    You will almost certainly run out of file handles before you hit a limit of port counts. Your system might also have limits related to firewall state tracking. But I suspect It would be somewhat protocol/application dependent. – Zoredache Jun 20 '13 at 07:35

2 Answers2

5

The client connects to the server on the port that it is already listening on. No new port is needed to accept an incoming connection.

David Schwartz
  • 31,449
  • 2
  • 55
  • 84
  • 4
    You are assuming a simple TCP protocol like http/ssh here. Some protocols, like FTP, will open a port per connection. – Zoredache Jun 20 '13 at 07:33
  • 4
    @Zoredache: It is unhelpful to give an overly complex answer to an extremely simple question. There is a common misunderstanding about how ports are assigned and giving a complex answer will likely just help the misunderstanding persist. – David Schwartz Jun 20 '13 at 07:34
2

A server identifies a TCP connection by the source IP+port of the client. 2 clients can have the same source port as long as their IP addresses are different, so your server will never run out of ports.

If the connection identifier were only the port indeed you could run out of identifiers, because there are only 2^16 ports.

A newer protocol like QUIC uses its own connection identifiers. The IP+port are no longer used as identifiers. The result is that the client can keep using the connection when its IP changes.

  • QUIC uses UDP which uses IP. IP packets are tagged with source and destination [IP] address and port. This makes me disagree with your last paragraph, unless you meant to say something else than what I have understood. – Armen Michaeli Aug 23 '21 at 09:27