In a tcp connection, how is it possible that the server can handle more than 65535 clients in an instant?

I was reading this socket tutorial from Oracle and came across the following text:

If all goes well, the server accepts the connection. Upon acceptance, the server receives a new socket bound to the same local port, as well as its remote endpoint set to the client's address and port. It needs a new socket so that it can continue listening on the original socket for connection requests in an effort to satisfy the needs of the connected client.

Now, if I'm not mistaken, the port size is 16 bits, which limits the maximum number of ports to around 65K. This means that the server cannot handle more than 65535 connections at any one time if all of its ports are bound to the client's local port. Although some answers like this on stackoverflow indicate no active connection limit. What is true in this and what is wrong?

Edit 1: If the server cannot handle more than 2 ^ 16-1 connections, then how do websites like Google handle this limitation?

+3


source to share


2 answers


A unique TCP connection is defined by a unique combination of client IP address, client port, server IP, and server port. For a particular service server, the IP and port are constant (for example, port 80 for HTTP), but the client's IP address and port may change. Since the port range is only 1.65535, this means the server can handle a maximum of 65535 different connections from the same client IP.at the same time, since these are all possible unique combinations if only the port can be changed. But if there are several clients with different IP addresses, this limitation applies to each of these clients separately. If you look at the number of different possible IP addresses (IPv4 and IPv6), you will see that there is essentially no real limit to how many connections a server can theoretically handle.



In practice, each of these TCP connections takes memory on the server as the current state must be kept. Additional memory is required in the kernel and application to describe the file descriptor and protocol state of the application. This means that there is a practical limit based on machine resources, which can be less than 64KB, but also more, depending on the system and its configuration.

+3


source


They use something like NAT (Network Address Translation) for your ISP. You can access another computer behind the router because your router displays routes to a PC within the company.



eg. Google's data center does the same. Mapping "Google.com" to another internal server, allowing them to accept over 65K connections.

-1


source







All Articles