Enter a domain name in the address bar, hit Enter, what happened to this process?

Macroscopically, enter a domain name in the address bar and search for the IP address of the target server through the domain name. This process relies on a DNS server. The DNS server resolves the IP address mapped by the domain name and communicates with the Web server through the IP address, and the communication protocol is HTTP

After the Web server receives the user’s request, it will go to the backend to execute the result. The execution result is sent back to the browser in the form of response message. The browser receives an inexplicable message, which only the programmer can understand. Rendering process, parsing HTML, performing loading logic, including external files required for page loading, including JS, CSS, etc., drawing layers

What is the HTTP protocol? How does it relate to the Web site you see?

Hypertext Transfer Protocol (HTTP) is a communication protocol that allows hypertext Markup Language (HTML) documents to be sent from a Web server to a client’s browser

Web is a global, dynamic and cross-platform distributed graphic information system based on hypertext and HTTP. The websites we visit are all network services built on the Internet, providing a graphical and easy-to-access intuitive interface for visitors to find and browse information on the Internet. Documents and hyperlinks organize the information nodes on the Internet into an interconnected network

HTTP protocol Structure

HTTP is built on TOP of TCP/IP and is a subset of TCP/IP. TCP/IP protocol is a set of protocols related to the Internet. Is a system consisting of four layers of protocols: application layer, transport layer, network layer and data link layer

Application layer: Generally refers to the written application, which determines the application services provided to users. The application layer can communicate with the transport layer through system calls. Eg: FTP, DNS, HTTP, etc.

The transport layer; Data transfer between two computers in a network connection is provided to the application layer through system calls. There are two different protocols at the transport layer: TCP and UDP. TCP is connection-oriented and reliable, but inefficient, while UDP is connectionless and efficient, but slightly more reliable

TCP three-way handshake: A TCP connection must be established before data can be transmitted. To ensure the reliability of the two parties, TCP adopts the three-way handshake policy when the two parties establish a connection. First handshake: The client sends a connection request packet with the SYN flag. Then the client enters the SYN_SEND state and waits for the confirmation from the server. Second handshake: After receiving a SYN packet from the client, the server sends an ACK message to confirm the SYN packet. At the same time, it sends its own SYN request. The server puts the information into a packet segment (SYN+ACK packet segment) and sends it to the client. At this point, the server enters the SYN_RECV state. Third handshake: After receiving a SYN+ACK packet from the server, the client sends an ACK packet to the server. After the ACK packet is sent, the client and the server enter the ESTABLISHED state to complete the TCP three-way handshakeCopy the code

Network layer: Used to handle packets that flow over the network. Packets are the smallest unit of data transmitted over the network. What route does this layer specify to reach and transmit packets to each other’s computers

Link layer: Processes the hardware that connects to the Network, including the control operating system, hardware device driver, Network interface Card (NIC), and optical fiber. Hardware categories are within the scope of the link layer

The role of DNS

Usually a page is accessed by a domain name or host name, because a domain name is more memorable than an IP address (a set of pure data). But TCP/IP uses IP addresses for access, so there must be a mechanism or service to convert domain names to IP addresses. DNS does this by providing domain name to IP address resolution services

The DNS resolution

Abide by the principle of proximity; First of all, the local computer will set up a relationship between the domain name and IP address that is frequently visited, and save it in the system file. Under normal circumstances, during DNS resolution, the system will preferentially look for the IP address from our host file. If found, use the address in the host file first; If no IP mapping is found for the domain name in the local host, the system sends a request to the local DNS server to query the IP address. If the local DNS server fails to find the IP address, the system sends a request to the DNS server of the next level up until the root server.

HTTP Protocol Features

1. Support client/server mode: The client sends a request to the server, and the server responds to the request and provides response services 2. Simple and fast: when a client requests services from the server, it only needs to send the request method and path. Request methods commonly used are GET, POST, etc., each method defines the type of contact between the client and the server is different. Because HTTP protocol is simple, the HTTP server program size is small, so the communication speed is very fast. Flexible: HTTP allows the transmission of any type of data objects. 4. No connection: The server is limited to processing only one request per connection. Stateless: HTTP is a stateless protocol. Stateless means that the protocol has no memory for transaction processing.