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
I am Man Guodong, a lecturer at 51CTO Academy. On...
The GSMA called on regulators worldwide to increa...
At 2:30 pm on July 28, 2020, the Maker Beijing 20...
On August 5, the "F5G Era Huawei Enterprise ...
The word 5G is "very hot". The topic of...
When checking the eligibility for number portabil...
This year's Double 11 event started very earl...
SpartanHost, also known as Spartan, is a foreign ...
The epidemic has given rise to many new formats a...
As the country vigorously promotes the developmen...
The progress of 5G has always been a key topic of...
From April 17 to 19, the 4th "National Civil...
While governments, enterprises, and research inst...
The Internet of Things has grown rapidly over the...
RF receiving systems usually use digital signal p...