Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between TCP and UDP

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly talks about "what are the differences between TCP and UDP". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what's the difference between TCP and UDP?"

First of all, it is emphasized that the TCP/IP protocol is a suite of protocols. It includes many protocols, and UDP is just one of them. It is named TCP/IP protocol because TCP and IP protocols are two very important protocols, so they are named after them.

When the difference between the two protocols is actually used, you only need to remember that "packet loss usually does not occur when TCP normally connects to send data (excluding other factors in the upper and lower layers), but it is very common for UDP to cause packet loss."

1. Connection-based and connectionless

2. Requirements for system resources (more TCP, less UDP)

3. The structure of UDP program is simple.

4. Stream mode and Datagram mode

5. TCP ensures the correctness of data, and UDP may lose packets.

6. TCP guarantees the order of data, but UDP does not.

From the above analysis, some people may think that, given the reliable transport protocol of TCP, it must be better than UDP, but it is not. The following examples illustrate this problem:

TCP is used in situations where reliable transmission is necessary at the transport layer. Because it is oriented to links and has mechanisms such as sequence control and retransmission control, it can provide reliable transmission for applications.

On the other hand, UDP is mainly used for communications or broadcast communications that require high-speed transmission and real-time performance. Let's take an example-when talking on an IP phone, if you use TCP, the data will be retransmitted if it is lost in the transmission graph, but this will not be able to transmit the caller's voice smoothly, resulting in a normal communication. With UDP, it will not be retransmitted. As a result, there will be no problem of significant delay in the arrival of sound. Even if some data is lost, it will only affect a small number of calls. In addition, UDP is also used in multicast and broadcast channels instead of TCP.

TCP (Transmission Control Protocol, Transmission Control Protocol) is a connection-oriented protocol, that is, a reliable connection must be established with the other party before sending and receiving data. A TCP connection can only be established through three "conversations". The process is very complex, so simply describe the simple process of these three conversations:

1) Host A sends a connection request packet to host B: "I want to send you data, can I?" This is the first conversation.

2) Host B sends a packet to host A that agrees to connect and requests synchronization (synchronization is two hosts, one is sending and the other is receiving, coordinating work): "Yes, when will you send it?" This is the second conversation.

3) Host A sends another packet to confirm host B's request for synchronization: "I'll send it now, you take it!" This is the third dialogue.

The purpose of three "conversations" is to synchronize the sending and receiving of data packets. After three "conversations", host A formally sends data to host B, which is also a prerequisite to ensure reliable transmission.

1. UDP is a connectionless protocol. Before transmitting data, the source does not establish a connection with the terminal. When it wants to transmit data, it simply grabs the data from the application and throws it onto the network as soon as possible. On the sending side, the speed at which UDP transmits data is only limited by the speed at which the application generates data, the ability of the computer, and the transmission bandwidth; at the receiving end, UDP puts each message segment in the queue, and the application reads one message segment from the queue at a time.

2. Because the transmission data does not establish a connection, there is no need to maintain the connection state, including transceiver status, etc., so a server can transmit the same message to multiple clients at the same time.

3. The title of the UDP packet is very short, only 8 bytes, and the extra overhead compared to the 20-byte packet of TCP is very small.

4. The throughput is not regulated by the congestion control algorithm, but only limited by the data rate generated by the application software, the transmission bandwidth, and the performance of the source and the terminal host.

5. UDP uses best efforts to deliver, that is, reliable delivery is not guaranteed, so the host does not need to maintain a complex link state table (which contains many parameters).

6. UDP is message-oriented. The message handed over by the sender's UDP to the application is delivered down to the IP layer after the header is added. Neither split nor merge, but retain the boundaries of these messages, so the application needs to choose the appropriate message size.

We often use the "ping" command to test whether the TCP/IP communication between the two hosts is normal. In fact, the principle of the "ping" command is to send UDP packets to the other host, and then the other host acknowledges the receipt of the data packet. If the message of whether the packet has arrived is fed back in time, then the network is open.

The ping command is used to detect whether the host can communicate with the host. If it is not possible to ping to a host, it means that a connection cannot be established with that host. The ping command uses IP and Network Control Information Protocol (ICMP) and therefore does not involve any transport protocols (UDP/TCP) and applications.

The ICMP protocol stipulates that the destination host must return an ICMP echo reply message to the source host. If the source host receives a reply within a certain period of time, the host is considered reachable.

At this point, I believe you have a deeper understanding of "what's the difference between TCP and UDP". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report