The difference between tcp and UDP

TCP/IP model

The TCP/IP model is the foundation of the Internet, and it is the general term for a series of network protocols. These protocols can be divided into four layers, namely the link layer, network layer, transport layer and application layer.

  • Link layer: Responsible for encapsulating and de-encapsulating IP packets, sending and receiving ARP/RARP packets, etc.
  • Network layer: responsible for routing and sending packet messages to the target network or host.
  • Transport layer: Responsible for grouping and reorganizing messages, and encapsulating messages in TCP or UDP protocol format.
  • Application layer: Responsible for providing users with applications, such as HTTP, FTP, Telnet, DNS, SMTP, etc.

Reference: HTTP protocol of Web basic knowledge

UDP

  1. Connectionless
  2. There are unicast, multicast, and broadcast functions
  3. UDP is message-oriented
  4. No congestion control, unreliability.
  5. The header overhead is small, and it is very efficient when transmitting data messages.

The UDP header has only 8 bytes, which is shorter than the 20-byte header of TCP.
2 bytes source port 2 bytes destination port 2 bytes length (user datagram length) 2 bytes checksum

When calculating the checksum, a pseudo header of 12 bytes should be added between the UDP user data packets, but when calculating the checksum, it is temporarily added in front of the UDP user datagram to obtain a temporary UDP user datagram. The checksum of IP datagram only checks the header of the IP datagram, and the checksum of UDP checks both the header and the data together.

TCP

  • Connection-oriented
  • Each TCP connection can only have two endpoints, that is, point-to-point: the connection endpoint is called a socket or socket = (ip address: port number)
  • Byte stream oriented
  • TCP provides reliable
  • Provides full-duplex communication

Extension: http based on tcp/ip dns based on udp

Guess you like

Origin blog.csdn.net/HZ___ZH/article/details/113246465