Enjoy love and honor, will feel the joy of life. — Shagil Shuo

Start:

The background of HTTP and its evolution since 1.0 is not much to explain. Interested readers can learn on their own. The content and progress of this chapter are summarized by reading the Turing series of Illustrated HTTP, plus their own Internet search.

TCP/IP layer

An important aspect of the TCP/IP family of protocols is layering. The TCP/IP protocol family is divided into four layers:

  • The application layer
    • The application layer determines the communication activities when providing application services to users.
    • For example, FTP (File Transfer Protocol) and DNS (Domain name System) services and HTTP
  • The transport layer
    • The transport layer provides data transmission between two computers in a network connection to the upper application layer.
    • The transport layer has two different protocols:TCP(Transmission Control Protocol) andUDP(User Datagram Protocol)
      • The two have very big difference, need to master emphatically
        • Connection:
          • TCP is connection-oriented. A secure connection (three-way handshake) must be established before data can be sent
          • UDP No connection, do not need to establish a connection before sending data
        • Safety:
          • TCP is safe and reliable, no error, no loss, no repetition, and in sequence.
          • UDP connectionless is unreliable. Data is sent as much as possible, but the risk of packet loss is high. Data sequence is not guaranteed
        • The number of connected objects
          • TCP supports only one-to-one communication
          • UDP supports one-to-one, one-to-many, and many-to-many communication objects
        • Performance:
          • TCP packets are 20-60 bytes long and cost a lot
          • The UDP packet title is short, only 8 bytes
        • order
          • TCP sorts packets using the SEQ sequence number. UDP does not sort packets.
        • Usage scenario:
          • TCP is suitable for transmission with low efficiency and high accuracy and reliability, such as file transfer
          • UDP is suitable for high efficiency, low accuracy scenarios such as (QQ chat, IP phone, video conference, live broadcast, etc.)
          • The truth is more complicated than that. Most use hybrid protocols, such as TCP for LAN, UDP for chat, and TCP for file transfer
  • The network layer
    • The network layer processes the data packets that flow across the network.
      • A packet is the smallest unit of data transmitted over a network
      • The network layer selects the best path for the packet to reach its destination
      • Supplement: Packet loss may occur, but it is managed by the transport layer, not the network layer.
  • The link layer
    • The link layer deals with the hardware that connects to the network.
    • Link (physical link) : a physical line from one node to a neighboring node without any other switching nodes in between.
    • Transparent transmission: indicates that data, regardless of the combination of bits, can pass through the data link layer as is, error-free.
    • Encapsulating frames: A frame is a transmission unit at the data link layer. Frame length is equal to the data portion of the frame plus the length of the beginning and end of the frame. Head and tail (determine frame boundaries).
    • Error checking: achieve incomparable error.

TCP/IP communication transmission flow

The communication transmission flow chart is as follows:

Screenshot source – Illustrated HTTP series


  • When using THE TCP/IP protocol family network communication, through the hierarchical order to communicate with each other
    • Sender: From the application layer down
    • Receiver: Proceeds from the bottom to the application layer
  • For example,HTTP, the client, as the sender, requests awebThe page data
    • First, the transport layer (TCP protocol)
      • The data received from the application layer (HTTP request packets) is split
      • Each packet is marked with a serial number (TCP can be sequential) and a port number
      • Forward to the network layer
    • Then the network layer (TCP/IP protocol)
      • On the basis of the data collated at the transport layer, the communication destination is addedThe MAC address
      • Forward to the link layer
    • The server receives the HTTP request sent by the client only when the data is transmitted to the application layer of the server

The request data sent by the client is bound to be wrapped by the header information of each layer during transmission, which is called encapsulation. Similarly, during transmission from the link layer to the application layer on the server, the header information at each layer is also stripped.

  • As shown in the figure below:

    Screenshot source – Illustrated HTTP series.

Protocols closely related to HTTP: IP, TCP, and DNS

IP:

  • IP protocol concepts responsible for transmission:

    • Almost all systems that use the Internet use THE IP protocol, which is of great importance
    • IP in the TCP/IP protocol family refers to the Internet protocol
    • Internet Protocol (IP)The Internet protocol is locatedThe network layer
  • Functions of the IP protocol:

    • Send various data packets to each other
    • Guarantees must be sent to the other party, subject to various conditions
      • One of the important conditions: IP address
      • Important Condition 2: Media Access Control Address (MAC).

The IP address indicates the address assigned to the node. The MAC address is the fixed address of the NIC. The IP address can be paired with the MAC address. The IP address is variable, but the MAC address does not change. *

  • ARP is used to communicate by MAC address

    • Communication between IP addresses depends on MAC addresses
    • On the network, communication parties usually pass through multiple computers and network equipment before connecting to each other
    • During the transfer, the MAC address of the next station transfer device is used to search for the next transfer target
    • In this case, ARP is used
      • ARP is a protocol used to resolve addresses. It detects the MAC address corresponding to the IP address of the communication party.
  • As shown in the figure below:

    Screenshot source – Illustrated HTTP series

TCP protocol:

  • Ensure reliable TCP protocol concepts:

    • Byte stream service: easy to transmit, the data is divided into segments of data packets
    • TCP provides the byte stream service to facilitate the transmission of large system data
    • The TCP protocol ensures that data reaches its destination
    • TCPAgreement inThe transport layer
  • How do you ensure that the data reaches its target?

    • The TCP protocol is usedThree-way handshakingstrategy
    • After sending the packet, TCP will confirm the success to the other party (UDP does not).
  • Know some identifiers

    • SYN: indicates the synchronization flag
    • ACK: Confirmation mark
    • FIN: Indicates the end flag

— SYN (Synchronize) and ACK (acknowledgement) indicate the use of TCP in a ‘handshake’.

  • 1. The sender sends a packet with the SYN flag to the sender.

  • 2. After receiving the packet, the receiver sends back a packet with the SYN/ACK flag to convey acknowledgement

  • 3. Finally, the sender sends back a packet with an ACK flag, indicating the end of the handshake.

  • Supplement: If any of the above processes is interrupted, try again

  • As shown in the figure below:

    Screenshot source – Illustrated HTTP series

To describe it colloquially:

  • A: ClientA SYN packet is sent to the server telling it that its initial sequence number is X
  • B: After the server receives the SYN packetReply to the client with an ACK acknowledgement packetTo indicate that they have received it and alsoSend a SYN packet telling the client that its initial serial number is Y;
  • C: After receiving these two packets, the client will reply to the server with an ACK packet to confirm receipt.

Wave: TCP disconnects, stops bidirectional data transmission, and reclaims resources

  • As shown in the figure below:

    Screenshot source – “Tencent Technology Engineering” public account

    To describe it colloquially:

  • A: The client sends A FIN packet to inform the server that there is no data transmission

  • B: The server sends back an ACK packet after receiving the packet, indicating that the server knows the packet.

  • C: Then the server sends a FIN packet to tell the client that there is no data transmission

  • D: The client sends back an ACK packet indicating that it knows

  • The four waves are completed, and the TCP connection is disconnected.

Supplement: can four waves become three waves? If the server receives the CLIENT’s FIN end flag packet to inform the client that there is no data transmission and has no data to send to the client, then the client’s ACK acknowledgement packet and the server’s own FIN end flag packet can be merged into one packet and sent. In this way, four waves can become three waves

DNS service:

  • DNS service concepts responsible for domain name resolution:

    • Domain Name System (DNS) : resolves Domain names to IP addresses.
    • IP address access does not apply to human memory, so domain name access is usually used
    • DNS maps domain names and IP addresses into a distributed database to facilitate Internet access
    • DNSThe protocol is located as the HTTP protocolThe application layer
  • The DNS protocol provides IP lookup by domain name or reverse lookup from IP, as shown in the following figure:

    Screenshot source – Illustrated HTTP series)

The relationship between each protocol and HTTP protocol and its role

  • As shown in the following figure, all protocols cooperate to complete communication and data exchange:

    Screenshot source – Illustrated HTTP series)

The URL and URI

  • URL and URI concepts:

    • A URL is a uniform resource locator. A URI is a uniform resource identifier
    • Uris are classified into three types: URL or URN OR (URL and URI) Almost all URIs are urls
    • Urls can be thought of as a subset of URIs.
    • When the browser accesses a Web page, the web address that needs to be entered is considered as the URL (Not nonsense
  • Uniform resource Locator URL

    • The URL isUniform Resource LocatorThe abbreviation of
      • A URL consists of the resource type, the domain name of the host that stores the resource, and the resource file name
      • (It can also be thought of as consisting of four parts: protocol, host, port, and path)
  • Uniform resource identifier URI

    • URI isUniform Resource IdentifierThe abbreviation of
      • Uniform refers to a Uniform format that facilitates processing of different types of resources
      • A Resource is anything that can be identified, most of which can be a Resource
      • Identifier refers to an object that can be identified, also known as an Identifier
    • Review:A URI is the location identifier of a resource identified by a protocol scheme
      • Protocol Scheme: Specifies the name of the protocol used to access resources
      • For example, when using HTTP (HTTPS), the protocol is HTTP (HTTPS).
    • Absolute URI format:
  • Zhihu sample

    • URI: indicates the ID number
    • URL: Human Agreement :// China/henan Province/Zhengzhou city/Guangming Road/building 3 no. 4 / Xiaoming. people

Conclusion:

A URI is an identifier, and a URL is a locator. Both can identify a unique resource. A URI implemented by an address rule can be called a URL.

You may also be interested in the following

  • Graphic HTTP 2
  • Three graphic HTTP
  • How are some of the apis implemented in # VUE3.0?
  • JavaScript reads local file configuration (compatible with lower IE versions)
  • # What do you ask about the front end of one year’s work experience?