Bo2SS

Bo2SS

9 Application Layer Protocol

Course Content#

Overview#

The architecture of network applications is mainly divided into Client/Server (CS) structure and Peer-to-Peer (P2P) structure.

  • The former is a client/server structure, such as WeChat, QQ, and games.
  • The latter is a peer-to-peer structure, also known as a peer-to-peer architecture, such as Thunder, Baidu Cloud.
    • When communicating between processes, there is no clear distinction between client and server. The initiator is the client, and the provider is the server.

Application services require reliable data transmission, throughput, timeliness, and security. Different applications have different requirements for network services, such as whether data can be lost, bandwidth requirements, and time sensitivity, so different application layer protocols and transport layer protocols are created:

  • Application layer protocols define the types of exchanged messages, message syntax, field semantics, and sending and response rules, similar to the three elements of network protocols (syntax, semantics, synchronization).
  • Transport layer protocols
    • TCP: Provides reliable data transmission for connection-oriented services.
    • UDP: Provides lightweight transport services that do not provide reliable data transmission.
  • PS
    • The socket is the interface between the application and the network, and its control over the transport layer is limited to selecting the transport layer protocol and setting parameters.
    • UDP can implement reliable data transmission on its own.

WEB and HTTP Protocol#

WEB Terminology: Object, Hypertext Markup Language (HTML), Uniform Resource Locator (URL), WEB page, WEB browser, WEB server (httpd, apache, tomcat)
HTTP: Hypertext Transfer Protocol

  • HTTP Actions: Request message, Response message
  • Characteristics of HTTP
    • No need to worry about data loss
    • Stateless protocol, the server does not store client-related state information
    • The HTTP server is always open and has a fixed IP
    • Uses CS structure
  • Non-persistent connection and persistent connection, also known as short connection and long connection
    • HTTP belongs to short connection. After the server responds to the request, it will notify TCP to disconnect, so it will repeatedly connect and disconnect for multiple objects.
    • The HTTP request process includes TCP three-way handshake, and the request is generally included in the third handshake until the corresponding file is received.
  • Request message
    • Request methods:
      • GET - Retrieve
      • POST - Submit form
      • HEAD - Test, check if it is accessible, do not need to get all data
      • PUT - Transfer data to the remote end (PUT is idempotent, but POST is not)
      • DELETE - Delete remote data
    • Header field names include browser types, etc.
  • Response message
    • The phrase is generally a description of the status code.
    • Common status codes and phrases:
      • 200 OK
      • 301 Moved Permanently
      • 400 Bad Request
      • 404 Not Found
      • 505 HTTP Version Not Supported
  • User-Server Interaction - COOKIE
    • COOKIE header lines are added to both request and response messages
    • The corresponding COOKIE file is managed by the browser on the user side
    • Maintain a database on the server side
    • A client host that has never requested the jd server will create its COOKIE after making a request and return it to the client;
    • When the client requests the jd server again next time, the server will return specific data based on the COOKIE.
    • PS:
      • The server can generate a user profile based on client behavior, which can be bound to COOKIE.
      • Companies may share databases.
  • WEB Cacher🌟
    • Also known as a proxy server, such as CDN.
    • Scenario: Massive users accessing data from a single server will cause the server to crash due to excessive traffic.
    • Optimization process: The browser first accesses the WEB cacher. If the desired data is not found, it will search for data upstream and finally return the data and store it in the WEB cacher.
    • Advantages: Reduce response time for client requests, reduce communication volume in data centers, and improve application performance.
    • PS: The WEB cacher periodically requests updated data from upstream servers.

HTTPS Protocol#

HTTPS: SSL-encrypted transmission protocol with security

HTTPS adds the SSL/TLS (encryption/decryption) process to the middle of HTTP communication.

Characteristics of HTTPS:

  • It requires applying for a certificate from a CA and requires payment;
  • It is an SSL-encrypted transmission protocol with security, while HTTP is a plaintext transmission protocol;
  • It uses a completely different connection method from HTTP, and the ports are different. The former is 443, and the latter is 80.

HTTP/2 Protocol#

New feature: Connection multiplexing. There is no synchronous limitation, and multiple messages can be transmitted at once without one-to-one correspondence.

FTP Protocol#

FTP: File Transfer Protocol

Users connect to remote servers and are presented with a remote desktop folder that users can operate on.

Dual Connection - FTP TCP connections:

  • Control connection: Port 21, long connection;
  • Data connection: Port 20, short connection.
  • Characteristics: Suitable for scenarios with low concurrency, can simplify business implementation.

PS: Less used by individual users, generally serving local area networks.

SMTP, POP3, IMAP Protocols#

Email-related, earliest Internet services

Starting from User A's agent, through SMTP, connecting to their own mail server, then connecting to User B's mail server, and finally reaching User B's agent.

  • The mail server checks whether the email content is compliant;
  • The SMTP protocol is only responsible for pushing, and the last step is User B actively requesting to pull based on other protocols.

PS:

  • Does not communicate directly with user hosts
  • Based on TCP at the lower level

DNS Protocol#

Converts hostnames/domain names to IP addresses; Provides load balancing services

  1. Domain name resolution
  2. Load balancing: Redirects the same domain name to different suitable IP addresses based on traffic, mainly used for traffic distribution.

Problems with centralized DNS:

  • Single point of failure: A small problem will affect the entire system (microservices are popular now, reducing the coupling between various services)
  • Large communication capacity
  • High latency when the distance is far
  • Difficult to maintain (banks also have this problem now, with low system versions, making it difficult to migrate)

DNS Domain Name System

  • Root DNS servers, there are 13 on the Internet, none of them are in China
  • Top-level domain DNS servers, abbreviated as TLD, such as com, cn
  • Authoritative DNS servers, such as Tencent and other DNS service providers
  • Local DNS servers, there may be multiple, such as local area networks, schools

DNS resolution process:

The host to local DNS is recursive, the host only sends one request, and the local DNS returns only when it gets the result.

The local DNS initiates the request iteratively, and retries if it fails. You can feel it by looking at the image.

DNS Records

  • Name: Name/Host/Alias
  • Value: IP address/Response address/Destination address
  • Type: Type of record
  • TTL: The valid time of the domain-IP relationship, that is, the time cached locally

Common types include:

You can try adding DNS records in your own DNS service platform~

PS: The readability of standardized hostnames is slightly weaker. You can refer to DNS records - CloudFlare

Additional Knowledge#

  • Three elements of network protocols: syntax, semantics, synchronization (traceable)
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.