What is the URL
A URL is the Uniform Resource Locator (URL), the most common form of Resource identification. A URL describes a specific location of a resource on a specific server. They can specify how to obtain resources from a precise, fixed location.
The URL describes the protocol, server, and local resource.
Browsers are based on HTTP, and HTTP is an application-layer protocol. HTTP doesn’t have to worry about the details of network traffic and is left to TCP/IP. TCP:
- Error-free data transmission.
- Sequential transmission (data always arrives in the order it was sent).
- Unsegmented data flow (data can be sent at any time).
The HTTP protocol is on top of TCP. HTTP uses TCP to transmit its packet data.
Parsing the URL
When the user enters a complete URL, the browser begins to parse the composition of the URL in order to find the resource address. The general syntax of most URLS is as follows:
<scheme>://<user>:<password>@<host>:<port>/<path>; <params>? <query>#<frag>Copy the code
Almost no URL contains all of these components. The three most important parts of a URL are scheme, host, and path. If the URL does not contain a port, the browser will use port 80 by default.
DNS domain name Resolution
What is DNS?
Domain Name System (DNS) is an application-layer protocol. In fact, DNS works for other application-layer protocols, including but not limited to HTTP, SMTP, and FTP, and resolves the host Name provided by the user into an IP address.
The following figure shows the DNS query process.
-
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. If yes, the operating system invoks the IP address mapping to resolve the domain name.
-
If the hosts does not contain the mapping of the domain name, the DNS server searches the cache of the local DNS resolver to check whether the mapping exists. If yes, the DNS server returns the mapping to complete the domain name resolution.
-
If there is no corresponding url mapping between hosts and the local DNS resolver cache, it will first look for the preferred DNS server set in the TCP/ IP parameter, here we call it the local DNS server. When receiving the query, this server will return the resolution result to the client if the domain name to be queried is included in the local configuration zone resources. Domain name resolution is complete. The resolution is authoritative.
-
If the domain name to be queried is not resolved by the local DNS server, but the server has cached the url mapping, the IP address mapping is invoked to complete the domain name resolution. The resolution is not authoritative.
-
If the local DNS server fails to resolve the local zone file and cache, the DNS server queries the domain name based on the forwarder configured on the local DNS server. If the forwarder mode is not used, the local DNS sends the request to the 13 root DNS servers. After receiving the request, the root DNS server determines who manages the domain name (.com). 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 a request and cannot resolve it itself, it will find a next-level DNS server address (http://qq.com) that manages the.com domain and send it to the local DNS server. After receiving the address, the local DNS server searches for the http://qq.com domain server and repeats the preceding operations until it finds the www.qq.com host.
-
If the forwarding 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.
From the client to the localDNS
The server is a recursive query, and the interactive query between DNS servers is an iterative query.
Establishing a TCP Connection
TCP
What to send depending on the current state (regular or star) :
Normal state | Said Ming | Send to send | Star status | Send to send |
---|---|---|---|---|
CLOSED | Shut down | RST, ACK | ||
LISTEN | Listen for connection requests (passively open) | |||
SYN_SENT | SYN issued (active open) | SYN | SYN_SENT* | SYN, FIN |
SYN_RCVD | The SYN has been sent and received. Wait for an ACK | SYN, ACK | SYN_RCVD* | SYN, FIN, ACK |
ESTABLISHED | Connection established (data transfer) | ACK | ESTABLISHED* | SYN, ACK |
CLOSE_WAIT | FIN is received. Wait for application shutdown | ACK | CLOSE_WAIT* | SYN, FIN |
FIN_WAIT_1 | Has been closed, send FIN; Wait for the ACK and FIN | FIN, ACK | FIN_WAIT_1 | SYN, FIN, ACK |
CLOSING | Both ends closed at the same time; Wait for an ACK | FIN, ACK | CLOSING* | SYN, FIN, ACK |
LAST_ACK | Received FIN has been closed; Wait for an ACK | FIN, ACK | LAST_ACK* | SYN, FIN, ACK |
FIN_WAIT_2 | Has been closed; Waiting for the FIN | ACK | ||
TIME_WAIT | Wait state of up to 2 M S L after active shutdown | ACK |
There are seven extended states defined in TCP, all of which are called star states. They are SYN_SENT*, SYN_RCVD*, ESTABLISHED *, CLOSE_WAIT *, LAST_ACK *, FIN_WAIT_1 * and CLOSING *.
TCP
Processing order of inputs
When TCP receives a packet segment, the control information (SYN, FIN, ACK, URG, AND RST flags, as well as possible data and options) carried in it is not in an arbitrary order, nor is it self-determined by the various implementations.
A transition from the CLOSED state to the SYN_SENT state indicates that a SYN segment has been sent. In the figure, this method is not used, but each status box is marked with the type of segment to be sent in that state. For example, when in the SYN_RECV state, a packet segment with the SYN is sent, including an acknowledgement (ACK) of the received SYN. When in CLOSE_WAIT state, an ACKNOWLEDGEMENT (ACK) of the received FIN is issued.
We do this because, in TCP, we often need to deal with segments that can cause multiple state transitions. Thus, when processing a segment, it is the final state of the connection at the end of the segment that is important, because it determines the content of the response. If TCP is not used, the state changes at most once after receiving a packet segment, except when receiving a SYN/ACK packet segment.
Three-way handshake
The connection between the client and the server is established through the three-way confirmation phase, known as the TCP three-way handshake.
For the first time,
The client sends a SYN packet. The sending number is set to X. The client enters the SYN_SENT state and waits for the response from the server.
The second time
After receiving a SYN packet, the server must confirm the syn(ACK = X + 1) from the client. Therefore, the server must send SYN =Y to the client to confirm that the server has received the request. The server sends ACK + SYN to the client, and the server enters the SYN_RECV state.
The third time
After receiving the SYN + ACK packet from the server, the client sends an ACK packet (ACK =Y+1) to the server. After the ACK packet is sent, the client and server enter the ESTABLISHED state (TCP connection succeeds) and complete the three-way handshake.
For example
For example, you are walking down the road and you see a friend coming up to you in front of you. You wave to your friend (the first handshake).
Your friend sees you greeting him, but your friend is too far away to be sure if it was the greeting, so your friend points to himself and motions to you (second handshake).
You see your friend’s face and movement, you need to give your friend a positive, at this point, you nod (third handshake).
At this point you and your friend chat with each other (TCP connection).
Four times to wave
Because TCP connections are full-duplex, each direction must be closed separately.
The principle is that when a party completes its data sending task, it can send a FIN to terminate the connection in that direction. Receiving a FIN only means that there is no data flowing in that direction. A TCP connection can still send data after receiving a FIN.
The first party to close will perform an active close, while the other party performs a passive close.
TCP
The client sends oneFIN
To shut down data transfer from the client to the server.- The server receives this
FIN
It sends back oneACK
To confirm that the number is the received number plus 1. andSYN
The same, oneFIN
Will occupy a serial number. - The server closes the client’s connection and sends a
FIN
To the client. - Client send
ACK
The packet is acknowledged and the acknowledgement number is set to the received number plus 1.
Wave example
You and your friend chat, chat, suddenly think of girlfriend lost the key, you are home to open the door, now delayed half an hour, scared cold sweat out, think of durian…
I’ll talk to you next time (first wave).
When your friend heard that, he thought he had to hurry back, so he told you to hurry back. (Second wave).
Then, your friend leaves and waves goodbye (third wave).
You see your friend say goodbye, you say goodbye to your friend (fourth wave).
When you get back, you’ll need to play with your durian.
Page rendering
See the next article on Browser Rendering Principles (How performance can be optimized to reduce rearrangements and redraws)
The last
Reference article:
1. Authoritative guide to HTTP.
2, DNS principle and its resolution process [wonderful analysis].
3. Elaborate volumes of TCP-IP