How is the information sent and received after entering a URL (address) from the browser?

What happens when a URL is entered into a browser?
From the perspective of network transmission (how the protocols cooperate)
insert image description here
1. The first part of the preparation before sending
1. The browser will first query the corresponding IP address according to the domain name here
(1) first check the browser's own Cache
(2) check the hosts file again
(3) check the DNS server
first check the nearest DNS server, and then check the DNS server of the upper level

2. The browser will construct an HTTP request,
which contains the domain name information just now (the information entered by the user)

3. The browser will call the socket API of the operating system, and hand over the HTTP request to TCP for further processing. The TCP protocol needs to construct a TCP datagram.
(1) Before sending the TCP datagram, a three-way handshake is required to establish a connection.
The SYN/ACK involved in the three-way handshake here also needs to pass through the network layer, data link layer, and physical layer, and then encapsulated in turn to reach the peer server before being distributed again.
(2) For specific data transmission, the sender will further hand over the TCP data to the IP protocol for an encapsulation.

4. The network layer encapsulates the datagram into an IP datagram, and further encapsulation
may be multiple IP datagrams. The IP protocol will also automatically perform the packetization process, and then hand over the data to the data link layer.

5. The data link layer will encapsulate this data into an Ethernet data frame.
When constructing the frame header, it needs to be mapped to the mac address according to the IP. This construction process relies on the ARP protocol, and then the data is passed to the physical layer.

6. The physical layer converts data into electrical signals and continues transmission.

2. The forwarding process in the middle of the second part of the road
7. The electrical signal goes along the network cable and reaches the next device (router).
The router will divide the received data.
(1) The physical layer hands the data to the data link layer
(2) The data link layer hands it to the network layer
(3) The router gets the IP datagram in the network layer
(4) Takes out the destination IP and queries the routing table , to find the next transmission target, and further find the mac address of the next transmission target.
(5) Re-encapsulate (deliver data to the data link layer and physical layer)
where the source mac and destination mac are changed

3. The third part, after reaching the receiving party
8. When the data arrives at the receiving party (Sogou server), the data still needs to continue to be shared.
Layer-by-layer analysis
(1) The physical layer converts the photoelectric signal into an Ethernet data frame and hands it to the data link layer
(2) The data link layer parses out the IP datagram and hands it to the network layer (both involve crc checks, if It is found that the checksum is incorrect, indicating that the data is wrong, and it is discarded directly)
(3) The IP protocol is analyzing, and a datagram is parsed out. (The IP header contains the protocol type)
This parsing process may also involve the process of grouping packets.
(4) Then find the corresponding process according to the port number in the TCP datagram, and put the data into the receiving buffer of the corresponding socket.

9. The application program calls the corresponding socket API to read data from the TCP receiving buffer, and the application program parses the data according to the HTTP protocol to obtain the URL in it. Get the /root path according to the path specified in the URL.

10. The server will internally configure the path / and map it to a specific index.html (or other name) html file. The server will read this file, construct the content of this file into an HTTP response data, and then call the socket API to send it.

11. Repeat the encapsulation process, and the response data sent by the server must also be encapsulated layer by layer, and finally become a photoelectric signal transmitted on the physical layer.

Fourth, the forwarding process in the middle of the fourth part of the road
12. The photoelectric signal reaches the next router, and the router repeats the demultiplexing process, resolves to the IP layer, takes out the destination IP, checks the routing table to find where the next device is, and proceeds again encapsulation.

13. Reach the next router, repeat the process of demultiplexing and encapsulation, and finally reach the user host.

5. The fifth step is to reach the first sender
14. The user host repeats the sharing process, takes out the data in turn, and finally hands it over to the application program.

15. The browser gets the HTTP response message, parses the message, obtains the html content in it, and renders it according to the html.

16. Since html may contain some tags such as img, link, and script, which may trigger a second request, the browser will construct a corresponding HTTP request and send it to the server based on the information in the tag, and then repeat from 1.

Guess you like

Origin blog.csdn.net/stitchD/article/details/123975360