The difference between TCP and UDP, how does TCP ensure reliable transmission?

Table of contents

OSI seven layer model

Which layer does TCP and UDP belong to

The difference between TCP and UDP, how does TCP ensure reliable transmission?

What are the protocols of the data link layer?

What is the difference between http and https?

Summarize


In the Internet protocol suite, TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are the two most basic data transmission protocols. They each have their own characteristics and uses, and have a wide range of applications. This article will introduce the difference between TCP and UDP in detail, and discuss in depth how TCP ensures reliable transmission.

OSI seven layer model

OSI (Open Systems Interconnection) seven-layer model, the seven layers are:

  1. Application Layer (Application Layer): Responsible for processing data of user programs, such as email and file transfer.
  2. Presentation Layer: Responsible for managing data encryption and decryption, as well as data format conversion.
  3. Session Layer (Session Layer): Responsible for establishing and maintaining communication sessions.
  4. Transport Layer (Transport Layer): Responsible for end-to-end data transmission, such as reliable byte streams and unreliable data packets.
  5. Network Layer: Responsible for data routing, sending data from source address to destination address.
  6. Data Link Layer (Data Link Layer): Responsible for the transmission of data on a physical network, such as Ethernet.
  7. Physical Layer: Responsible for the establishment and maintenance of physical connections, as well as the physical transmission of data.

This model is an abstract model used to describe network communication. Each layer defines how to process data and provides a standard interface. This enables different devices and systems to communicate with each other, realizing network interoperability.

Which layer does TCP and UDP belong to

Both TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) belong to the transport layer.

TCP is a connection-oriented, reliable, byte stream-based transport layer communication protocol. It is defined by RFC 793 of the IETF. TCP establishes an end-to-end connection between the application layer and the network layer, which ensures the reliability and sequence of data transmission. It is suitable for data transmission scenarios that require reliability and sequence. Protocols such as HTTP, FTP, and SMTP are based on TCP protocol.

UDP is a connectionless, unreliable transport layer protocol. It does not need to establish a connection, but simply sends data packets to the destination address, does not guarantee the reliability and sequence of data transmission, and does not have the functions of flow control and congestion control. UDP transmits data between the application layer and the network layer, and is suitable for scenarios where data transmission requires real-time and efficiency, such as real-time audio and video transmission, online games, etc.

Both TCP and UDP are transport layer protocols, belonging to the fourth layer in the computer network architecture, located above the network layer and below the application layer.

The difference between TCP and UDP, how does TCP ensure reliable transmission?

TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) have the following differences:

  1. Connection mode: TCP is connection-oriented, and a connection needs to be established before transmitting data. UDP is connectionless and can directly send data to the destination host without establishing a connection.
  2. Reliability: TCP provides reliable data transmission, which guarantees the sequence and integrity of data, can detect the loss and duplication of data packets, and retransmit them. UDP does not have these mechanisms, so it is not suitable for transmitting important data.
  3. Flow control: TCP has a flow control mechanism, which can control the data rate sent according to the processing capability of the receiver, so as to prevent the receiver from being unable to process too much data. UDP has no flow control mechanism.
  4. Congestion control: TCP has a congestion control mechanism. When the network is congested, it will slow down the rate of sending data to avoid further aggravation of network congestion. UDP has no congestion control mechanism.

TCP ensures reliable transmission through the following mechanisms:

  1. Establishing a connection: In TCP, the two communicating parties need to establish a connection through a three-way handshake process. This process establishes the serial number and confirmation number of both parties, which is ready for subsequent data transmission.
  2. Packet numbering: TCP divides the transmitted data into data segments and numbers each data segment. The receiver can restore the original data according to the number.
  3. Confirmation and timeout: After sending data, the sender will wait for the receiver's confirmation. If the receiver has received the data, it sends an acknowledgment. If the sender does not receive an acknowledgment within a certain amount of time, it will retransmit the data. This mechanism ensures that data will not be lost or duplicated.
  4. Flow control: TCP uses a sliding window mechanism for flow control. The receiver tells the sender its own window size, and the sender controls the amount of data sent according to the window size. This mechanism can prevent the receiver from being unable to process too much data.
  5. Congestion control: TCP uses congestion control algorithms such as slow start, congestion avoidance, fast retransmission, and fast recovery to avoid network congestion. When network congestion is detected, the sender will slow down the rate at which data is sent to avoid further aggravation of network congestion.
  6. Data verification: TCP will add a checksum when sending data, and the receiver will check the checksum after receiving the data. If the data is corrupted or inconsistent, the receiver notifies the sender to resend the data.

What are the protocols of the data link layer?

Data link layer protocols mainly include the following:

  1. PPP (Point-to-Point Protocol): Mainly used in point-to-point serial links, it provides two data bit rates, synchronous and asynchronous, and supports multiple network protocols, such as IP, IPv6, ARP, RARP, etc.
  2. HDLC (High-level Data Link Control Protocol): It is a data link layer protocol based on synchronous transmission, mainly used for data link layer communication in LAN.
  3. SLIP (Serial Line Interface Protocol): It is a simple serial line protocol, mainly used for terminal connection of UNIX system.
  4. PPPoE (Point-to-Point Protocol over Ethernet): It is a protocol for establishing point-to-point connections on Ethernet, mainly used for broadband Internet access.
  5. ARP (Address Resolution Protocol): It is used to convert IP address to MAC address for data transmission in LAN.
  6. RARP (Reverse Address Resolution Protocol): Used to convert MAC addresses to IP addresses, usually used on diskless workstations.
  7. MSTP (Multiple Spanning Tree Protocol): It is a data link layer protocol that divides a switching network into multiple domains and forms multiple spanning trees in each domain. The spanning trees are independent of each other to achieve fast recovery and load balancing. .
  8. RPR (Rapid Ring Protection Protocol): It is a link layer protocol specially applied to Ethernet rings, which can quickly detect network faults and restore them.
  9. RPL (Resilient Packet Ring): It is a combination of the advantages of SDH/SONET, Ethernet and other ring network technologies. It combines the intelligence of IP, the economy of Ethernet, and the high bandwidth and high reliability of optical fiber ring network. It is a Layer 2 protocol that can meet the requirements of the high-demand metropolitan area network.

These protocols have different characteristics and advantages in different application scenarios, and the appropriate data link layer protocol can be selected according to actual needs.

What is the difference between http and https?

The main differences between HTTP and HTTPS are as follows:

  1. Security : HTTP is a hypertext transfer protocol and information is transmitted in clear text, so it is not a secure protocol. On the contrary, HTTPS is a transmission protocol encrypted with a secure ssl certificate, so it is more secure than HTTP.
  2. Port number : The default port for HTTP is 80, and the default port for HTTPS is 443.
  3. Protocol : HTTP is a stateless protocol, while HTTPS is a network protocol built by SSL+HTTP that can perform encrypted transmission and identity authentication.
  4. Cost : HTTP is free, while HTTPS requires a fee. This is because HTTPS uses SSL encryption and needs to purchase an SSL certificate, so the cost of deployment is relatively high.
  5. Browser address display method : In the browser, the HTTP address display method is "http://", while the HTTPS address display method is "https://".

Overall, the main differences between HTTP and HTTPS are security, port numbers, protocols, cost, and how browser addresses are displayed.

Summarize

There are significant differences between TCP and UDP in terms of data transmission. TCP is a connection-oriented, reliable, byte-stream-based transport protocol, suitable for applications that require data sequence and integrity.

UDP is a connectionless and unreliable transport protocol, suitable for applications that require high real-time performance and efficiency. TCP ensures reliable data transmission through mechanisms such as connection establishment, data packet numbering, confirmation and timeout, flow control, congestion control, and data verification. Understanding the difference between TCP and UDP and their working principles will help us choose the appropriate data transmission protocol in different application scenarios.

Guess you like

Origin blog.csdn.net/wq2008best/article/details/132620345