1. Obtaining an IP address
  2. The TCP/IP three-way handshake establishes a link
  3. The browser sends an HTTP request to the Web server
  4. Browser rendering
  5. Disconnect with four waves

1. Obtain the IP address

DNS is used to resolve urls into IP addresses

The IP address corresponds to a real physical machine, and the IP address is like a person’s ID card is unique, the user requests the server, only need to enter the unique IP address assigned to the server. However, IP addresses are not easy to be memorized, so semantic domain names are used to replace IP addresses. A domain name may correspond to multiple IP addresses. For example, if a user enters www.baidu.com and the domain name corresponds to multiple IP addresses, the domain name resolution server assigns one IP address to the user based on certain rules.

DNS resolution process:

1. Enter www.qq.com domain name in the address box of the browser. The operating system checks whether the address mapping exists in the local hosts file.

2. If the hosts does not contain the mapping of the domain name, check whether the local DNS server cache contains the mapping of the domain name. If yes, return the address directly to complete the domain name resolution.

5. If the local DNS server fails to resolve the local zone file and cache, the DNS server queries the domain name according to the Settings of the local DNS server (whether the forwarder is configured). If the forwarder mode is not used, the local DNS sends the request to the 13 root DNS servers. It returns an IP address that is responsible for that TOP-LEVEL DNS server. After receiving the IP address information, the local DNS server contacts the server in charge of the.com domain. If the server in charge of the.com domain receives the request and cannot resolve it, it will find the address of the next-level DNS server (QQ.com) that manages the.com domain to the local DNS server. When the local DNS server receives the address, it searches for the QQ.com domain server and repeats the preceding operations until it finds the www.qq.com host.

6. If the forward mode is used, the DNS server forwards the request to the upper-level DNS server for resolution. If the upper-level DNS server fails to resolve the request, it either finds the root DNS or forwards the request to the upper-level DNS server. Whether the local DNS server uses a forward or a root prompt, the result is returned to the local DNS server, which in turn returns the result to the client.

2. The TCP/IP three-way handshake establishes the connection

There are three processes (three handshakes) to establish the connection:

  1. The client sends a request to the server to establish a connection (the client calls the server)
  2. When the server receives the request, it signals that it agrees to connect.
  3. The host, after receiving the signal to connect, sends a confirmation signal to the server (client: “Hello hello, can you hear me?”). )

Why three handshakes? If two handshakes are used, the following dialog only has the first two sentences: The client sends a connection request packet, but the packet remains in the network due to network reasons. After receiving the request, the server establishes a connection and waits for the client to transmit data. At this point, the client does not know what is happening, resulting in a waste of server resources.

3. The browser sends an HTTP request to the Web server

The client is ready to communicate with the server after establishing a TCP/IP connection.

  1. The browser sends an HTTP request based on the resolved IP address and port number. The HTTP request includes the header and body. The header contains the request mode (GET and POST), the request protocol (HTTP, HTTPS, FTP), the request address IP, and the cache cookie. The body contains the requested content. For example, GET www.google.com/ HTTP/1.1
  2. When the server receives the request, it decides how to get the HTML file based on the content in the HTTP request
  3. The server sends the resulting HTML file to the browser

Get generates one TCP packet, post two (get and POST are the most detailed summary of the portal)

  1. On a GET request, the browser sends the headers and data together, the server responds with 200 (returns data),
  2. For a POST request, the browser sends headers, the server responds with 100 continue, the browser sends data, and the server responds with 200 (return data).

The client requests static and dynamic resources:

  1. Static resource: If the client requests a static resource, the Web server searches for the file in the corresponding path of the server based on the URL address, and then returns an HTTP response to the client, including the status line, response header, and response body.
  2. Dynamic resources: If the client requests dynamic resources, the Web server will call the CGI/VM execution program to complete the corresponding operation, such as querying the database, and then return the query result data set, and the result of the run – HTML file back to the Web server. The Web server then returns the HTML file to the user.

4. Browser rendering

  1. DOM Tree: Parsing HTML to build a DOM(DOM tree)
  2. CSS Tree: Parsing CSS to build CSSOM(CSS tree)
  3. Render Tree: CSSOM and DOM work together to generate a Render Tree
  4. Layout: According to the Render Tree browser, which nodes in the page, and the relationship between each node and CSS, thus knowing the location of each node and geometric attributes (rearrange)
  5. Paint: Draw the entire page from calculated information (redraw)

5. Wave four times to disconnect

When the client has no data to send, it needs to disconnect to release server resources.

  1. Client: I have no data to send and am going to disconnect
  2. Server: I have received your request, I still have data to send, you wait
  3. Server: my data has been sent, can disconnect
  4. Client: OK, you disconnect (client monologue: I will close the connection after double the maximum segment lifetime. If I get the message from the server again, I know the server didn’t get the message and I send it again).

Finally, the server receives a message from the client and disconnects, and the client closes the connection.