Difference Between TCP and UDP & TCP three-way handshake

Source: Internet
Author: User

TCP-the transmission control protocol provides connection-oriented and reliable byte stream services. Before the customer and the server exchange data with each other, a TCP connection must be established between the two parties before data can be transmitted. TCP provides timeout resend, discard duplicate data, test data, traffic control, and other functions to ensure data can be transferred from one end to the other.

UDP-the User Datagram Protocol is a simple datagram-oriented transport layer protocol. UDP does not provide reliability. It only sends the data from the application to the IP layer, but it cannot guarantee that the data can reach the destination. Because UDP does not need to establish a connection between the client and the server before transmitting the datagram, and there is no timeout and re-transmission mechanism, the transmission speed is very fast.

Main differences between UDP and TCP:

UDP does not necessarily provide reliable data transmission.

In fact, this Protocol cannot ensure that the data is accurate to the destination.

UDP is very effective in many ways.

When a program aims to transmit as much information as possible as soon as possible (where any given data is of relatively low importance), UDP can be used.

ICQ short messages use UDP to send messages.
Many programs will use separate TCP connections and separate UDP connections. Important Status information is sent along with reliable TCP connections, while the main data stream is sent over UDP.

TCP aims to provide reliable data transmission and maintain a virtual connection between devices or services that communicate with each other.

TCP is responsible for data recovery when data packets are unordered, lost, or damaged during delivery. It completes the recovery by providing a sequence number for each packet it sends. Remember, each packet is considered as an independent unit at the lower network layer. Therefore, data packets can be sent along completely different paths, even if they are components of the same message. This route is similar to the way the network layer processes segments and reassembles data packets. It is only at a higher level.
To ensure that data is correctly received, TCP requires a confirmation (ACK) when the target computer successfully receives the data ). If the corresponding Ack is not received within a certain time limit, the data packet will be re-transmitted. If the network is congested, this re-transmission will lead to repeated data packets. However, the receiving computer can use the serial number of the data packet to determine whether it is a duplicate data packet and discard it if necessary.

TCP and UDP Selection 

If we compare the structure of UDP packets and TCP packets, it is obvious that UDP packets do not have the complex reliability and Control Mechanism of TCP packets. Similar to TCP, UDP supports multiple applications on one host as well as the number of source ports and destination ports. A 16-bit UDP packet contains a Byte Length header and Data Length. The verification code field enables it to perform overall verification. (Many applications only support udp, such as multimedia data streams, and do not generate any additional data. Even if you know the damaged packets, do not resend them .)
Obviously, when the performance of data transmission must be in the integrity, controllability, and reliability of data transmission, TCP is certainly the choice. UDP is the best choice for audio and multimedia applications that emphasize transmission performance rather than transmission integrity. When the data transmission time is so short that the previous connection process becomes the whole traffic subject, UDP is also a good choice, such as DNS switching. The reason for establishing SNMP on UDP is that the designer believes that when the network is blocked, the low overhead of UDP gives it a better chance to transmit and manage data. The rich functions of TCP sometimes lead to unpredictable low performance, but we believe that in the near future, reliable point-to-point connections of TCP will be used in most network applications.

 

 

PS: When a TCP connection is established, three handshakes are required. Why not two handshakes?

Answer: because the network is unreliable, the number of handshakes is not necessarily a reliable connection.

The minimum number of handshakes is three. Because the two handshakes, the response end does not know whether the initiator has received the response message, so it cannot be sure whether the connection has been established. Only after receiving the response from the sender can both parties confirm that the connection has been established.

TCP three-way handshake protocol:

In TCP/IP, TCP provides reliable connection services and uses three handshakes to establish a connection.

First handshake: when a connection is established, the client sends the SYN Packet (SYN = J) to the server and enters the syn_send status. Wait for the server to confirm;

The second handshake: when the server receives the SYN packet, it must confirm the customer's Syn (ACK = J + 1) and send a SYN Packet (SYN = K), that is, the SYN + ACK packet, the server enters the syn_recv status;

The third handshake: the client receives the server's SYN + ACK package and sends the ACK (ACK = k + 1) Confirmation package to the server. After the package is sent, the client and server enter the established status, complete three handshakes.
------------------------------
After three handshakes are completed, the client and the server start to transmit data.

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.