4

Let me give some background as to what I'm asking, to make it clear:
In the context of Server-Client TCP-communication over the internet, when a server process is running, a client process can initiate a TCP connection to the server. It does so by initiating a three-way-handshake.
At the end of the hand shaking phase, the accept() function (invoked on the welcoming socket at the server side) will set up a new socket - a connection socket - dedicated for the new incoming client-connection.
From now on, until this connection will be terminated, the server will communicate with the client through the connection socket.

Since every client gets a connection socket, and TCP-socket on the server is uniquely identified by a four-tuple (src IP address, src port number, dest IP address, dest port number), and a port number is a 16-bit number, then how can servers support more than 65,536 clients (well, 65,536 minus the reserved ones)?

so.very.tired
  • 2,958
  • 4
  • 41
  • 69
  • http://serverfault.com/questions/533611/how-do-high-traffic-sites-service-more-than-65535-tcp-connections – CodeCaster Sep 05 '15 at 13:13
  • Add redundancy by introducing multiple CD servers (farms)--assuming resources are the constraint. – Brad Christie Sep 05 '15 at 13:15
  • And also http://stackoverflow.com/questions/2332741/what-is-the-theoretical-maximum-number-of-open-tcp-connections-that-a-modern-lin. Try searching. – CodeCaster Sep 05 '15 at 13:21

1 Answers1

2

The tuple has three other members besides the client port. If one of those varies the connection can happen. Usually, the clients port and IP will vary enough to allow the server to use one IP and one port. If required the server can use multiple IPs and multiple ports, tough.

usr
  • 168,620
  • 35
  • 240
  • 369
  • So... two "connection sockets" on the server can have **the same local port** as long as some other factor in that four-tuple is different? – so.very.tired Sep 05 '15 at 13:22
  • Yes. If a web server accepts something on port 80 the connection will be on port 80. Not just the listening. – usr Sep 05 '15 at 13:23
  • @so.very.tired: if the server is listening on a single IP/port, all connected clients will have the same server-side IP/port, and be differentiated by the client-side IP/port. If the server is listening on multiple IPs/ports, two connected clients from the same machine can use the same client-side IP **and** port, as long as they are each connected to a different server-side IP/port. This is not common, but it is possible. The client-side port is typically chosen randomly, but can also be static via `bind()`. – Remy Lebeau Sep 06 '15 at 17:23