This is the fifth day of my participation in the August Wen Challenge.More challenges in August

Let me show you one of the layers of computer network architecture I found:

Then let’s get to the theme:

A, general

A complete HTTP request goes through the following flow:

  1. Perform DNS resolution on the URL and find the CORRESPONDING IP address of the server.
  2. The TCP connection is established after three handshakes.
  3. The client sends a request to the server
  4. The client sends a request header to the server
  5. The server receives the request
  6. The server sends the response header to the client
  7. The server sends response information to the client
  8. The request is completed after the server closes the TCP connection with four waves

Second, the rounding

1. The DNS

As mentioned in the last article, DNS runs on top of UDP and uses port 53. The DNS domain name resolution process is as follows:

  1. Look up the cache from your browser
  2. If not, search for it in the system’s own cache
  3. If you still can’t find it, try looking for it in the hosts file
  4. When none of the previous three procedures has been found, recursively go to the DNS server to find it

After parsing, it will be recorded in the local cache for a period of time, which is convenient for next use.

2. Three handshakes

The so-called three-way handshake means that the client sends three packets to establish a TCP connection with the server after obtaining an IP address.

My understanding of the three-way handshake (simplified version) :

First handshake:

  • The client generates a random sequence number and sends it to the server and waits for a response. (Client -> Server) Aston launch point occurs.

Second handshake:

  • After receiving the serial number, the server sends a serial number to the client and waits for the client to confirm it. (Server -> Client)

Third handshake:

  • After receiving the data from the server, the client confirms that the data is correct and sends the confirmation to the server. After the server receives the confirmation, the connection is established successfully and the two parties enter the connection state. (Client -> Server)

Generally, the TCP connection port number is 80.

3. Send the request

The request sent by the client to the server can be broken down into three parts:

(1) request

This parameter describes the request mode, the name of the requested resource, and the VERSION of the HTTP protocol used

GET/index. HTTP / 1.1 HTMLCopy the code

(2) the request header

Describes cache information, client identity information, request address, environment information, and so on

Referer: https://www.baidu.com Cookie:gsScrollPos=; _ga = GA1.2.329038035.1465891024; _gat=1 User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36...Copy the code

(3) the body of the message

When we use POST, PUT and other request modes, we usually need to pass data to the server, which is stored in the message body (GET request message body in the url “? “). Later, not here), this is not necessary.

4. Response information

The response from the server to the client can also be broken down into three parts:

(1) status code

Represents the result (status) of the server’s processing of the request.

HTTP / 1.1 200 OKCopy the code

Common status codes are:

category The reason the phrase
1XX Informational (Informational status code) The accepted request is being processed
2XX Success (Success Status code) The request is successfully processed
3XX Redirection (Redirection status code) Additional action is required to complete the request
4XX Client Error (Client Error status code) The server cannot process the request
5XX Server Error The server failed to process the request
  • 200: The request is successful and returned successfully
  • 301: Request location update, return new address and request again
  • 400: Cannot parse the request content
  • 401: The request is not authenticated through HTTP
  • 403: The requested resource is not accessible
  • 404: Requested resource not found or does not exist
  • 500: The server is faulty

(2) the response headers

Basic information about the server.

Connection:keep-alive Content-Encoding:gzip Content-Type:text/html; Charset = UTF-8 Date:Fri, 24 Jun 2016 06:23:31 GMT Server:nginx/1.9.12 Transfer-encoding :chunkedCopy the code

(3) the response body

That is, the request data returned by the server to the client, such as HTML text, images, and JSON.

Requests and responses, for example, can be seen in Chrome’s Developer tools, Network.

5. Wave four times

The reverse of the three-way handshake is the four-way wave, one used to establish and one used to break a TCP connection. The four waves were also named because a total of four packets were sent during the disconnection.

Four waves I understand (simplified version) :

First wave:

  • The client sends a wave request and collects the serial number of the previously established connection into the request packet and sends it to the server, indicating that there is no more request and waiting for confirmation. (Client -> Server)

Second wave:

  • After receiving the wave request, the server sends a packet to the client to confirm the wave request and close the connection. (Server -> Client)

Third wave:

  • The server sends a packet to the client, indicating that the connection is disconnected and waiting for confirmation. (Server -> Client)

Fourth wave:

  • After receiving the disconnection request from the server, the client acknowledges the request and sends a packet to the server. After receiving the request, the server disconnects. If the client does not receive any response after waiting for a period of time, the connection is disconnected and closed.

If we add the following information to the request header or response header:

Connection:keep-alive
Copy the code

Indicates that the TCP connection remains open after being sent, and the browser can continue sending requests over the same connection. Keeping the connection saves the time required to establish a new connection for each request and saves network bandwidth

Third, summary

I this HTTP request split is not very detailed, because the TCP/IP protocol is not particularly familiar with, such as when there is time to do a detailed understanding.


I hope you can point out any questions in the comments section, AND I will correct them in time.

New people on the road, but also include more. I am MoonLight, a fledgling small front end.