Features and Differences Between TCP and UDP

Source: Internet
Author: User

Before learning about the features of TCP and UDP, we should first understand what is the concept of data packets.

  • 1. Data Packets

A packet is a data unit in TCP/IP communication. It is also called a "packet ". In a packet switching network, a single message is divided into multiple data blocks. These data blocks are called packages, which contain the address information of the sender and receiver. These packages are then transmitted in one or more networks along different paths and combined at the destination. A data packet consists of the "Destination IP address", "source IP address", and "net data" parts, including the packet header and packet body. The packet header is a fixed length and the packet body length is not fixed, the length of each field is fixed. The headers of request packets and response packets are consistent. The difference is the definition of the packet body.
The structure of the data packet is very similar to what we usually write. The destination IP address is the recipient's address, and the source IP address is the source of the data packet, it is equivalent to the sender's address, while the net data is equivalent to the content of the letter. It is precisely because data packets have such a structure that computers with TCP/IP protocols can communicate with each other. When we use a network based on the TCP/IP protocol, packets are actually transmitted in the network.

  • 2. TCP features

2.1 connection-oriented

"Connection orientation" means that a connection must be established with the other party before formal communication. For example, if you call someone else, you must wait until the line is connected and the other party picks up the microphone to talk to each other. TCP (Transport Control Protocol) is a connection-based protocol. That is to say, a reliable connection must be established with the other party before sending and receiving data.

2.2. Three sessions

A TCP connection can be established only after three "conversations". The process is very complicated. Here we only provide a simple and visual introduction. You only need to understand this process. Let's take a look at the simple process of the three conversations: host a sends a connection request packet to host B: "Can I send data to you ?", This is the first conversation; host B sends a packet to host a that agrees to the connection and requires synchronization (synchronization means that two hosts are sending, receiving, and coordinating): "Yes, when will you send it? ", This is the second conversation. host a sends another packet to confirm that host B's request is synchronized: "I will send it now, let's proceed !", This is the third dialogue. The purpose of the three "dialogs" is to synchronize the transmission and receipt of data packets. After the three "dialogs", host a formally sends data to host B.

2.3 low communication efficiency and high reliability
The TCP protocol can provide reliable communication connections for applications, so that the byte stream sent by a computer is sent to other computers on the network without error. for data communication systems with high reliability requirements, the TCP protocol is often used to transmit data.

  • 3. UDP features

3.1 Non-connection-oriented

"Non-connection oriented" means that you do not need to establish a connection with the other party before the formal communication, and send the connection directly regardless of the other Party's status. This is very similar to the popular mobile phone text message: when you send a text message, you only need to enter the phone number of the other party and then OK.
User Data Protocol (UDP) is the protocol corresponding to TCP. It is a non-connection-oriented protocol. Instead of establishing a connection with the other Party, it directly sends data packets!
3.2. High communication efficiency and low reliability
UDP is applicable to applications that transmit only a small amount of data at a time and do not require high reliability. For example, we often use the "ping" command to test whether the TCP/IP communication between two hosts is normal. In fact, the principle of the "ping" command is to send UDP packets to the other host, then, the host of the other party confirms that the packet is received. If the message indicating whether the packet arrives is returned in time, the network is connected. For example, four data packets () are sent during a ping operation by default (). As you can see, the number of data packets sent is 4 packets, and the number of packets received is also 4 (because the recipient's host will send back a packet to confirm receipt ). This fully demonstrates that UDP is a non-connection-oriented protocol and does not establish a connection. Because the UDP protocol does not have a connection process, its communication efficiency is high; but also because of this, its reliability is not as high as that of the TCP protocol. Qq uses UDP to send messages, so sometimes messages cannot be received.

  • 4. Differences Between TCP and UDP

TCP and UDP have their own strengths and weaknesses, and are suitable for communication environments with different requirements. The differences between the TCP protocol and the UDP protocol are shown in the appendix.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.