B
B
balun922014-12-08 11:40:28
Java
balun92, 2014-12-08 11:40:28

How does one network socket handle many connections?

According to Java, they write in the literature that after the .accept () method for a client that has already passed a three-time tcp handshake, a new "network" socket is created, through which further interaction with the client takes place. ( source ) And the original server socket (which I hang up for example on port 80 for http server'a ) is used only to establish new connections.
I have doubts about this. I do not open ports for clients in the firewall, I have one open - the server one.

Question: how is it possible to handle a large number of clients through one port?

ps I realized that for each client a regular socket is created, which apparently unambiguously characterizes one client (by the connection port + client ip).
It turns out that on the server side, all requests are routed through one server socket, bound on the port? How is routing done?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
jcmvbkbc, 2014-12-08
@balun92

It turns out that on the server side, all requests are routed through one server socket, bound on the port? How is routing done?

Only requests to establish a connection pass through the server socket. After the connection is established, a new socket is created on the server side, binding the IP of the server on which the request was received, the port of the server, the IP of the client that sent the request, and the port of the client. This set of information is enough to determine that the incoming packet should appear on this socket, and when writing to the socket, to understand where to send the packet.

S
Sergey, 2014-12-08
@begemot_sun

Each client has an outgoing port and IP. Accordingly, the OS can determine which socket to send data to when the TCP packet arrives.

S
Sergey, 2014-12-08
Protko @Fesor

socket != port

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question