TCP (Transmission Control Protocol) and UDP (User Data Protocol) both belong to the TCP/IP protocol suite. The TCP/IP protocol suite includes Hypertext Transfer Protocol (HTTP), File Transfer Protocol (FTP), Telnet, Internet Protocol (IP), Internet Control Message Protocol (IMCP), etc. Today, the Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) are running on the transport layer of the protocol suite. OSI protocol model, TCP/IP protocol model Difference between TCP and UDP Connectivity TCP is a connection-oriented protocol. Before sending or receiving data, a reliable connection must be established with the other party. The three handshakes to establish a connection and the four waves to disconnect the connection lay a reliable foundation for data transmission. UDP is a connectionless protocol. Before data transmission, the source and the terminal do not establish a connection. The sender throws the data onto the network as quickly as possible, and the receiver reads the message segments from the message queue. reliability TCP provides reliable delivery services and uses many methods during the transmission process to ensure reliable transmission services on the connection, such as numbering and confirmation, flow control, timers, etc., to ensure that data is error-free, not lost, not duplicated and arrives in order; UDP uses the best effort delivery possible, but does not guarantee reliable delivery. Message header The TCP message header has 20 bytes, which has a large overhead; the UDP message header has only 8 bytes, with a short header and small overhead. UDP message structure TCP message structure Message transmission The TCP protocol is byte stream-oriented and regards application layer messages as a string of unstructured byte streams. It is decomposed into multiple TCP message segments for transmission and then reassembled at the destination station. The UDP protocol is message-oriented and does not split application layer messages. It only retains message boundaries and sends one message at a time. After the receiver removes the message header, it passes the message intact to the upper-layer application. Throughput Control TCP congestion control, flow control, retransmission mechanism, sliding window and other mechanisms ensure transmission quality; UDP does not. Duplex TCP is only capable of point-to-point full-duplex communication; UDP supports one-to-one, one-to-many, many-to-one, and multi-stack interactive communications. Programming steps for TCP and UDP TCP Programming Steps UDP Programming Steps From the above TCP and UDP programming steps, we can see that the UDP server does not need to call listen and accept client connections, and the client does not need to connect to the server. In the UDP protocol, after either party establishes a socket, they can use sendto to send data and recvfrom to receive data, without having to worry about whether the other party exists or has sent data. Use cases for TCP and UDP In order to achieve the reliability of TCP network communication, complex mechanisms such as checksum, sequence number identification, sliding window, confirmation response, and congestion control are added, and a cumbersome handshake process is established, which increases TCP's consumption of system resources; TCP's retransmission mechanism and sequence control mechanism have a certain delay effect on data transmission, reducing transmission efficiency. TCP is suitable for application scenarios with low transmission efficiency requirements but high accuracy requirements, such as the World Wide Web (HTTP), file transfer (FTP), and email (SMTP). UDP is connectionless and unreliable. It delivers data as much as possible and has the characteristics of simple protocol, low resource requirements, fast transmission speed and high real-time performance. It is suitable for application scenarios with high requirements for transmission efficiency but low requirements for accuracy, such as domain name conversion (DNS) and remote file server (NFS). |
<<: Three key reasons why automakers are adopting 5G
>>: New iCONNECT, SD-WAN 3.0 architecture, launched
Hello everyone, I am Xiaolin. I received a privat...
MIIT releases three-year action plan for industri...
Through the connection of virtual network devices...
The overall flow chart is as follows: 1. URL pars...
Many service providers have deployed network func...
DiyVM continues its promotion this month, offerin...
[[345275]] During the National Day holiday, WeCha...
The latest report from market research firm Omida...
In the digital age, traditional fast-moving consu...
Overnight, 5G changed the world. First, Qualcomm ...
Positioning has become an important technology in...
The internet has become an integral part of our l...
Last week, we shared the news of RAKsmart's f...
[[430197]] Image from Baotu.com If the scenic spo...
Amazon may not be as well-known as Google, Apple,...