preface

When we want to browse a web page, we generally input the corresponding URL, which is actually the process of requesting the corresponding resources. So what does this process actually do?

Description of the process

  1. Search IP – The client searches for an IP address based on the domain name
  2. Establish a connection – The client connects to the server based on the IP address
  3. Intercommunication – The client communicates with the resource server
  4. Disconnect – The client is disconnected from the resource server

Detailed explanation of the specific process

1. To find the IP

  • If the search succeeds, the browser returns the CORRESPONDING IP address. If the search fails, go to the next step.
  • Search the DNS cache in the system. If the search succeeds, the corresponding IP address is returned. If the search fails, go to the next step.
  • Search for the hosts file in the system. If the search succeeds, the corresponding IP address is returned. If the search fails, go to the next step.
  • The system sends a request to the router. The router searches its cache and returns the corresponding IP address if the search succeeds. If the search fails, go to the next step.
  • The system sends the domain Name to the LDNS(local domain Name Server) and returns the CORRESPONDING IP address if the search succeeds. If the search fails, the LDNS sends a request to the Root Name Server to obtain the TOP-LEVEL DNS address of the domain. Then, the LDNS sends a request to the Root Name Server to obtain the TOP-LEVEL DNS address of the domain. Finally, the corresponding IP address of the domain name is obtained.
  • LDNS returns the IP address to the operating system and caches it;
  • The system returns the IP address to the browser and caches it;
  • The browser obtains the IP address and initiates a request to establish a connection.

2. Establish a connection – Three handshakes

After obtaining the corresponding IP address, the browser will initiate a request to establish a connection to the target server. The establishment of a connection is mainly divided into three steps, which is often referred to as the three-way handshake:

  • The browser sends a request to establish a connection with the server (hello, anyone?).
  • The server sends a response agreeing to establish a connection (hello, sure!).
  • The browser sends a request to the server to acknowledge the response and establishes a connection. B: Nice to meet you.

3. Communicate with each other

After establishing the connection, the main purpose of this connection comes, which is data interaction, which mainly says that the client requests data

  • The client sends a request for a page resource
  • The server returns the corresponding resource
  • After requesting the corresponding resource, the client may continue to request CSS, JS and other resources for page rendering

4. Disconnect the device

After data communication, disconnect the connection by “four waves”

  • The browser sends a request to the server to disconnect (I’m leaving);
  • The server sends a response to the browser that it received the request (I get it);
  • The server sends a disconnection request to the browser; (That’s it, I’m off)
  • The browser disconnects and sends a feedback request to the server, which disconnects when it receives it (ok, bye).

Pay attention to

Why does disconnection have to be so tedious four times?

Mainly because when the client tell the server to disconnect, the data server may not have been processed, so the server is first told the client has received the request, it want to disconnect and then when the server in the data processing is completed, then disconnect request and inform the client, the client receives the disconnect request and also after the notification server.

Reference: juejin. Cn/post / 684490…