web123456

15. The entire process of executing after entering a URL in the browser

1. Client browser passesDNSparsed toofIPaddress202.108.22.5Find the path from the client to the server through this IP address. The client browser initiates an HTTP session to 202.108.22.5 and then passesTCPEncapsulate the packet and input it to the network layer. 
2. In the client's transport layer, the HTTP session request is divided into packet segments and the source and destination ports are added. For example, the server uses port 80 to listen to the client's request. The client randomly selects a port such as 5000 by the system and exchanges it with the server. The server returns the corresponding request to the client's port 5000. Then use the IP address of the IP layer to find the destination.(Create tcpconnect)
3. The network layer of the client does not need to care about the application layer or the transport layer.The main thing is to find the routing table to determine how to reach the server, During this period, multiple routers may pass through, and these are all done by the router. I will not describe it too much, it is simply determined by looking up the routing table.Go to the server through that path. (IPThe important functions are addressing and routing
4
, the link layer of the client, the packet is sent to the route through the link layer
, through neighbor protocolFind a givenIPAddressMACaddress,Then send an ARP request to find the destination address. If you get a response, you can use the ARP request to answer the exchanged IP packets can now be transmitted, and then sendIPThe address where the packet arrives at the server. (IPTransfer the address toMAC


Event order

(1) The browser obtains the input domain name
(2) The IP address that the browser requests to DNS to resolve
(3) The domain name system DNS resolves the IP address of Baidu server

(4) The browser issues an HTTP request and requests Baidu homepage
(5) The browser establishes a TCP connection with the server (default port number 80)

(6)IPThe important functions are addressing and routing

(7) defines the protocol and hardware requirements required to output data through a physical network

The server sends the homepage file to the browser via HTTP response.
(7) TCP connection release
(8) The browser parses the homepage file and displays the web page to the user.


The agreement involved

(1) Application layer: HTTP (WWW access protocol), DNS (domain name resolution service)
DNS resolves the domain name as the destination IP, finds the server path through the IP, and the client initiates an HTTP session to the server, and then encapsulates the data packets through the transportation layer TCP protocol, and transmits them based on the TCP protocol.

(2) Transport layer: TCP (providing reliable data transmission for HTTP), UDP (DNS uses UDP transmission)
HTTP sessions will be divided into packet segments, adding source and destination ports; TCP protocol performs main work

(3) Network layer: IP (IP data packet transmission and routing), ICMP (providing error detection during network transmission), ARP (map the default gateway IP address of the machine into a physical MAC address)
Select the route for the data packet, the IP protocol performs the main work, reliable transmission of adjacent nodes, and the ARP protocol converts the IP address into a MAC address.

 

>>>After clicking on the URL, the DNS protocol of the application layer will resolve the URL to an IP address;

DNS search process:

1. The browser willCheck if there is any resolved IP corresponding to this domain name in the cacheaddress, if there is in the cache, the parsing process will end.

2. If the user's browser cache is not in the browser, the browser will look for the operating system cache.(hostsdocument)Is there any DNS resolution result corresponding to this domain name?

3. If not, a packet will be sent to the DNS server.DNSThe resulting IP will be parsed after the server is foundReturn the address to the user

 

>>>At the application layer, the browser will send an HTTP request to the web server;

The request header is: GET /HTTP/1.1

>>>In the transport layer, (transport data stream segments in the upper layer) HTTP packets are embedded in the TCP packet segment;

The TCP packet segment needs to be set up, the HTTP of the receiver (Baidu)The default port is 80The port of this machine is a 1024-65535Random integers between them, assuming here is 1025This TCPThe packet segment is headered by TCP (includingPort information of the sender and receiver)+ HTTPPacket composition.

 

>>>In the network layer, the TCP packet segment is embedded in the IP packet;

IP packets need to know the IP addresses of both parties.Native IPThe address is assumed to be 192.168.1.5, and the IP address of the recipient is 220.181.111.147 (Baidu). In this way, the IP packet consists of IP header (IP address information) + TCP packet segment.

 

>>> At the network interface layer, IP packets are embedded in data frames (Ethernet packets) and transmitted on the network;

The data frame contains the source MACAddress and destination MAC address (derived through ARP address resolution protocol). In this way, the data frame consists of the header (MAC address) + IP packet.

 

>>>The data packets are forwarded to the Baidu server through multiple gateways, requesting services on the corresponding port;

The service receives the sent Ethernet packet and starts to parse the request information and extracts it from the Ethernet packet.IPData Packet—>TCPSegment—>HTTP packet,andAssemble the valid data and pass it to the thread allocated in the corresponding thread pool for processing, in this process, generate the corresponding request, response object.

 

>>>After the request processing is completed, the server sends back an HTTPresponse;

The request handler reads the request and its parameters and cookies. It will read and update some data and store the data on the server. After processing, the data outputs information to the customer through the response object. The output information also needs to be spliced ​​with the HTTP protocol header, and then disconnected after closing. After disconnection, the server automatically logs out the request and response objects and releases the usage identifier of the corresponding thread (usually a request is processed by one thread alone, and in some special cases, one thread handles multiple requests).

The response header is: HTTP/1.1200 OK

 

>>>The browser reads the content of the HTTP response (HTTP response packet) in the same process, and then parses the received HTML page and displays the web page to present it to the user.

The client receives the return data, removes the corresponding header information, and forms a page HTML that can also be recognized by the browser.String information is translated into the corresponding page rule information displayed as page content by the browser.

 

 

1. By domain name → IPaddress
The process of finding an IP address passes through the browser cache, system cache, hosts file, router cache, and recursive search of the root domain name server in turn.

2. Establish TCP/IPConnection (three-way handshake process)

3. Send an HTTP from the browserRequest

4. The HTTP is forwarded through the router and the server's firewall.The request has reached the server

5. The server handles the HTTPRequest, return an HTML file

6. The browser parses the HTMLFile and displayed on the browser side

7. Note here:

HTTP The protocol is based on TCP/IPThe application layer protocol must first establish a TCP/IP connection when requesting HTTP data

It can be understood as follows: HTTPIt is a car, which provides a specific form of packaging or displaying data; Socket is an engine, which provides the ability to communicate networks.

The communication between two computers is nothing more than data communication between two ports.In what form the specific data will be displayed is defined by different application layer protocols.