How many clients connect to a port on the server, such as 80? (Translation)

原文:How do multiple clients connect simultaneously to one port, say 80, on a server? [duplicate]

 

 

Usually we use ServerSocket specified a port (eg 8080), then after multiple clients are using this on a socket on port 8080 and server-side communication connection. Or http server uses port 80 and is also more than one browser to connect communications. Why can this happen? Operating system processes in connection with multiple ports is how to distinguish?


 

Translation:

We are here talking about Socket connection:

1. Port identification is just a number, not a real physical port; 

The primary key (i.e., to distinguish between different socket) 2. a Socket connection is comprised of a five-tuple {SRC-IP, SRC-PORT, DEST-IP, DEST-PORT, PROTOCOL} composition, i.e., {source address, source port , destination address, destination port, protocol} composed of those who say the agreement does not contain a quad argument is wrong. 

3. A process can have multiple socket connection.

An example of a two clients connected to the servers with the same port 80, i.e., there are two socket connection: 

- socket1 {SRC-A, 100, DEST-X,80, TCP} 

- socket2{SRC-B, 100, DEST-X,80, TCP} 

Different address of Host A and Host B, two hosts are connected to the port 80 while the X server. Server how to handle this connection it is something we want to understand why a host with ports can monitor multiple client Socket connection.

Explanation: 

1. IP is because two different clients, the server can identify the Socket different; 

2. Even if the same IP address, different ports, it is possible to distinguish the server; 

3. As long as the server knows which socket request and receive relevant, then it can use this socket to properly respond to the client; 

4. If you need different ports for different socket, then not only a waste of server resources, and after each client connections serverSocket also allocated additional new port and client communications. Not necessary.

Examples Second, different processes can listen to the same port.

Therefore, the two processes use different protocols servers can listen on the same port.

If the identification is only a socket quad does not include the protocol {SRC-IP, SRC-PORT, DEST-IP, DEST-PORT}, it is not possible to simultaneously monitor different processes the same port. There is no agreement, then a client to connect to the same server has a listening port of the two processes, then there is no mechanism to determine if the client is a process to which is connected.

Operating system (particularly UNIX), can inherit the parent process of all files child processes described in File-descriptors (FD), and therefore the parent process A is listening on all socket, can also be used by all child processes processes A1, A2 monitor. But different process B is not the same listening port.


 

Personal understanding:

1 problem: how multiple clients simultaneously connected to a port on the server, such as 80?

A: Different servers and clients communicating via a communication port 80. After a socket is {SRC-IP, SRC-PORT, DEST-IP, DEST-PORT, PROTOCOL}, the server pentad listening port number 80, receives a connection request, based on the client's port number and ip 80 + server IP and port number to create a socket, you can then create a thread or a coroutine just created by the socket to communicate with clients.

2 questions: multiple clients simultaneously connected to a port (such as 80) on the server, whether new play another port to communicate?

A: The new server will not play port. 80-port server has been responsible for the client's request to listen, if there is a client request, the server always use the same socket in response to the first test (no need to assign another server port), then create a new socket (set according to five yuan ), then creates a thread or a coroutine just over a socket to the newly created and client communications. So the server from start to finish only takes a 80-port listening and communication.

3 Question: If there are one hundred thousand clients simultaneously connect to the server, if a 80-port can accommodate so many client connections to interact?

A: Whether a 80-port and can accommodate so many client interaction, this is the problem machine performance and the performance of the program.


 

reference:

Why multiple clients can be connected to the same port the server?

 

 

Guess you like

Origin www.cnblogs.com/zkfopen/p/11206612.html