Differences Between TCP and UDP

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.


The popular protocol on the Internet is the TCP/IP protocol, which has a definite definition of ports lower than 1024. They correspond to some common services on the Internet. These common services can be divided into TCP port (for connection) and UDP port (for non-connection.


When talking about TCP and UDP, we must first understand the meaning of "connection" and "No connection". Their relationship can be illustrated in an image metaphor, that is, making calls and writing letters. If two people want to call, they must first establish a connection-that is, the dialing at the time of the call, wait for the response-that is, after answering the call, the information can be transmitted to each other, and finally disconnect-that is, the phone is suspended. It is easy to write a letter. after entering the recipient's address, the recipient will be able to receive the email in the inbox. From this analysis, we can see that the establishment of a connection requires both parties to establish a channel to transmit information, after the sender sends a request to the connection information receiver for response, because the information is transmitted only after the recipient responds, and is transmitted in a channel, the receiver can completely receive the information sent by the sender, that is, the information transmission reliability is relatively high. But it is also because of the need to establish a connection that increases resource overhead (before establishing a connection, you must wait for the recipient to respond, in the process of transmitting information, you must confirm whether the information is transmitted or the corresponding signal is sent when the connection is disconnected.) The channel is exclusive and the connection cannot be established when the connection is disconnected, that is, a third party cannot make a call during the call. No connection sends information at the beginning (strictly speaking, this is not the beginning or the end), but only one-time transmission. It does not require the response from the receiver, therefore, to a certain extent, the reliability of information transmission cannot be ensured. Just like writing a letter, we only send the letter, but the recipient cannot be sure to receive it.


TCP is connection-oriented and has high reliability. Some services with high requirements generally use this protocol, such as FTP, telnet, SMTP, HTTP, POP3, etc, UDP is connectionless. Common services using this protocol include DNS, SNMP, and QQ. For QQ, it must be explained that before qq2003, only UDP protocol was used. Its server uses port 8000 to listen for any information, and the client uses port 4000, send information externally (it is not difficult to understand that the port is usually 4000 or the cause of the subsequent port in the QQ version of a common explicit IP address that shows the IP address information of a friend ), that is to say, the QQ program accepts and provides services, and supports the use of TCP protocol in later QQ versions.

 

Application

Application Layer Protocol

Supported transmission protocols

Email

SMTP (rfc82)

TCP

Remote Terminal Access

Telenet

TCP

Web

HTTP

TCP

File Transfer

FTP

TCP

Remote File Server

NFS

TCP or UDP

Stream multimedia

Exclusive

UDP or TCP

Internet phone number

Exclusive

Generally UDP

In the table, we can see that email, remote terminal access, web and file transfer all use the TCP protocol. The main reason for choosing TCP for these applications is that TCP provides reliable data transmission services, this ensures that all data will eventually reach its destination. We also see that internet phones generally run on UDP protocol, and both ends of an Internet phone application can send data at a certain minimum rate across the network. In addition, internet phones can tolerate data loss, both of these conditions are applicable to UDP and do not require reliable TCP transmission services.

In general, TCP can ensure that all data is transmitted, but UDP cannot, and they do not provide latency assurance. They do not provide latency assurance, which does not mean that time-sensitive applications cannot run on the current Internet, but applications use other methods to ensure these needs.

Original article address: Workshop

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.