1. Enter the url
We typed the url juejin. Im /timeline into the browser
2. DNS domain name resolution
This step is used to resolve domain names and obtain IP addresses.
The browser looks in the local cache to see if it has the IP address, and if it doesn’t, it starts asking the root server if it has the IP address for the domain name, and if it doesn’t, it looks up the domain server, and the process is iterative. This search way is like me to ask if there is this person in our county now, if there is no city to find, in no province to find inside. Then the province may not know the person but he knows who knows, and he will tell you the process of going to whom and who. When he finally gets the IP address, he caches it locally.
3. TCP connection (three handshakes and four waves)
And when you get the IP address then you can transfer the data over TCP. It takes three handshakes to establish a connection. Three handshakes let me put it my way.
Let’s suppose that two people are on the right and left of the road twice. John says to John on the other side of the road. Hi, I’m John. (first wave) Li Si hears and responds. I’m Li Si. I hear you, you’re Zhang SAN bo. (Second wave). Zhang SAN confirmed it was Li Si and said it was me, so we could transmit data.
At the first wave, the client sends an SNY packet to the server.
For the second wave, the server responds with an SNY and ACK packet to the client.
After receiving SNY and ACK packets for the third wave, the client responds with an ACK packet from the server
The two parties confirm each other’s information, and then the data can be transmitted.
4. The browser sends an HTTP request to the Web client
After a TCP connection is established, an HTTP request is made, which consists of three parts
Request method URI protocol/version
Request Header
Request body
5. Server-side processing
Handle requests and data
6. Wave four times
Start closing the connection as soon as the data is transferred. That’s the TCP four waves.
The client says to the server that my data is about to break
The server said ok, let me see if I have any data to send?
Server says I don’t have any data to wear. Let’s close the connection.
The client says ok, so I close the connection.
- First wave: The Client sends a FIN to stop data transmission from the Client to the Server, and the Client enters the FIN_WAIT_1 state.
- Second wave: After receiving a FIN, the Server sends an ACK to the Client. The ACK sequence number is +1 (the same as that for SYN, one FIN occupies one sequence number). The Server enters CLOSE_WAIT state.
- Third wave: The Server sends a FIN to disable data transfer from the Server to the Client, and the Server enters the LAST_ACK state.
- Fourth wave: After receiving the FIN, the Client enters the TIME_WAIT state and sends an ACK to the Server to confirm that the FIN number is +1. The Server enters the CLOSED state and waves four times.
Why does it take only three handshakes to establish a connection, but four waves to close it?
The three-way handshake is required for establishing a TCP connection because the TCP packet sent from the server to the client uses SYN and ACK as flag bits during the second handshake. SYN: Indicates that the server agrees to establish a connection. An ACK message informs the client that the server has received its request packet.
That is, SYN connection establishment packets and ACK acknowledgement packets are transmitted in the same handshake. Therefore, the three-way handshake is neither more nor less, ensuring that the two parties can communicate with each other.
The “four wave” is required for TCP connection release because the FIN release packet and ACK acknowledge packet are transmitted through the second and third handshake respectively. Why are connections made together and released separately?
When establishing a connection, the passive server completes the CLOSED phase and enters the Handshake phase without any preparation. It can directly return SYN and ACK packets to start establishing a connection. When releasing a connection, the passive server receives a request from the active client to release the connection but cannot release the connection immediately because necessary data needs to be processed. Therefore, the server sends an ACK message to confirm receipt of the packet and then returns a FIN packet to release the connection after the close-wait phase is complete.
So “three handshakes”, “four waves”.
The next step is browser-side rendering
7. Parse HTML
Parsing HTML into nodes that have relationships with each other creates a DOM tree
Analytical CSS. 8
Parse CSS into A CSS tree