This paper is participating in theNetwork protocols must be known and must be known”Essay campaign
preface
Let’s start with a picture drawn by some foreign bigwig
This diagram shows what happens when you type a URL into a browser
Analysis of the
1. Enter the url in the browser
- For example, enter www.baidu.com in the browser
2. The browser resolves the domain name
- Check whether the local hosts file has rules
- No HOSTS rule Sending DNS requests (local)
- If there is cache, the local DNS queries the root DNS server
- The root DNS tells the local DNS the domain name, and the local DNS sends a request to the domain server to return the address of the DNS server
- The local DNS sends a request to the DNS server to return the mapping between the domain name and the IP address. The IP address is returned to the user, and the corresponding relationship is saved in the cache. The next query is directly returned to the cache
3. Establish the TCP connection
- The local random port (1024-65536) initiates a TCP connection request to port 80 of the server. The request enters the kernel TCP/IP protocol stack, the firewall, and finally reaches the WEB program
- Establish a connection with three handshakes
- The client sends the SYN (Hello! I want to talk to you.
- Server confirms message SYN/ACK (ok, I’m free)
- Client return ACK handshake ends (ok, let’s get started)
4. The browser initiates an HTTP request
- GET POST PUT DELETE OPTION…
- Request header
- Request body
5. Server processing
- The Web server processes the request
- Invokes the appropriate resource and returns it to the client
- HTTP status codes (explained in another chapter)
6. The browser processes resources
- Parsing the HTML generates a DOM tree
- Parsing CSS to generate CSS rule tree, together to generate render tree
- GPU rendering display, the final display in the browser
- Repaint: Partially repaint
- Reflow: Redraw all
7. Close the TCP connection and wave four times
- The client sends the message FIN
- The server receives an ACK and waits to see if the transmission has not completed
- The FIN is returned after all transmission ends
- The client returns an ACK to close the TCP connection
In one sentence
Enter the URL in the browser => Perform DNS query and obtain the resource address => Establish a TCP connection (three-way handshake) => Send an HTTP request => The server processes the resource and returns it to the front end => The browser parses the resource and draws it on the page => Close the TCP connection (four-time wave)