G
G
Governor2021-12-11 20:06:01
Computer networks
Governor, 2021-12-11 20:06:01

How does the server send data to the client?

Hello.
For example, let's take a connection over TCP sockets. Let's say the client sent a request to the server, he accepted it, and created a connection, and when the need came, the server sends a message to the CLIENT.

The moment of sending by the server of the message to the client interests. That is, how does the server generally understand where to send the response if the client does not have a white IP address, which means that the client's host does not exist in the global network?
Even if the client has allocated a separate port, how can the server reach a host that is not on the WAN?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexey Cheremisin, 2021-12-11
@leahch

TCP has not only an IP address, but also a port. Both on the server side and on the client side. If on the server side the port is usually set statically (for example, 80), then on the client side it is selected dynamically from the unoccupied ones. As a result, each client receives its own unique IP-port pair, through which the server sends packets to the client socket. Thus, we can have a bunch of client connections on one computer, differing in different client ports for each connection to one server.

H
hint000, 2021-12-12
@hint000

Please confirm if it works like this.
Not at all. I'll try faster. To understand how NAT works, you need to sum up three facts:
1. Within the provider's client network, there is no problem that clients' addresses are grayed out. Because the provider himself assigns these gray addresses (automatically) and understands who is who, and where each client is located.
2. The provider remembers that such and such a client has established a connection with such and such a server, from such and such a port to such and such a port. Roughly speaking, remembers until the connection is broken.
3. The server's response does not go to your gray address, but to the white address of the provider itself.

A
Alexander, 2021-12-11
@NeiroNx

The server knows the IP address of the client. The network subsystem collects and sends the packet in which it is indicated (in a special zone), either to the network if the client is on the local network or to the main gateway, the gateway relays to the next gateway - until the packet reaches the client's gateway.
You can take Wireshark and see all these packets and what fields they have.

A
Alexander Karabanov, 2021-12-11
@karabanov

This is possible thanks to NAT
NAT did not always exist, it was invented as a temporary solution, but something went wrong.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question