The difference between TCP protocol and UDP Protocol (RPM)

Source: Internet
Author: User
Tags file transfer protocol

The difference between TCP protocol and UDP Protocol (RPM)
First we find out that the TCP protocol and the UCP protocol and the TCP/IP protocol, many people confused, has always been the TCP/IP protocol and the difference between the UDP protocol, I think it is not fundamentally clear network communication!
The TCP/IP protocol is a protocol cluster. It includes a lot of protocols. UDP is just one of them. The TCP/IP protocol is named because the TCP,IP protocol is two very important protocols, named after him.
The TCP/IP protocol set includes the application layer, the transport layer, the network layer, and the network access layer.
Among the application layers are:
Hypertext Transfer Protocol (HTTP): The basic protocol for the World Wide Web.
File transfer (TFTP Simple File Transfer Protocol):
Telnet, which provides remote access to other host features, which allows users to log on
Internet host, and execute commands on this host.
Network Management (SNMP Simple Network Management Protocol), the Protocol provides a way to monitor network equipment, as well as configuration management, statistical information collection, performance management and security management.
Domain Name System (DNS), which is used to convert a domain name and its public broadcast network nodes to an IP address on the Internet.
Second, the network layer includes:
Internet Protocol (IP)
Internet Control Information Protocol (ICMP)
Address Resolution Protocol (ARP)
Reverse Address Resolution Protocol (RARP)
Finally, the network access layer: The network access layer is also known as the host-to-network layer (host-to-network). The network access layer's capabilities include mapping IP addresses to physical address hardware, and encapsulating IP into frames. Based on the network interface of different hardware types, the network access layer defines the connection to the physical media.
Of course, I am not perfect here, the TCP/IP protocol is a science, each branch is a very complex process, but I believe that every student learning software development needs to be carefully understood.
Let me focus on the differences between the TCP protocol and the UDP protocol.
TCP (transmission Control Protocol, transmission Protocol) is a connection-oriented protocol, which means that a reliable connection must be established with each other before sending or receiving data. A TCP connection has to go through three "dialogs" to build up, and the process is very complex and simply describes the simple process of three conversations: Host A sends a connection request packet to Host B: "I want to send you data, OK?" "This is the first conversation; Host B sends a consent connection to host A and requires synchronization (synchronization is the two host one in the send, one in the receiving, coordination work) packet:" Can, when do you send? " "This is the second conversation; Host a then sends a packet to confirm that Host B's requirements are synchronized:" I'll send it now, you go on! " ", this is the third dialogue. Three times the purpose of the "conversation" is to synchronize the sending and receiving of packets, and after three "conversations", host a formally sends the data to Host B.
The detailed point says is: (the article partial reprint http://zhangjiangxing-gmail-com.iteye.com, mainly is this person to explain very in place, indeed very easy to make the person understand! )
TCP three-time handshake process
1 Host A to host B by sending a data segment containing a flag bit of the serial number to Host B, to host B to request a connection, through this data segment,
Host A tells Host B two things: I want to communicate with you, you can use which serial number as the starting data segment to respond to me.
2 when Host B receives a request from host A, it responds to host A with a data segment with a ACK (ACK) and a synchronous sequence number (SYN) flag bit, and also tells host a two things:
I have received your request, you can transfer the data, you need to use which pins XLR serial number as the starting data segment to respond to my
3 When host a receives this data segment, it sends a confirmation reply confirming that the data segment of Host B has been received: "I have received a reply and I am now going to start transmitting the actual data.
So 3 times the handshake is complete, and host A and Host B can transfer the data.
3-Time handshake features
No data for the application tier
SYN This flag bit will only be set when the TCP build connection is 1
SYN flag bit is set 0 after handshake completes

TCP establishes a connection for 3 handshakes, and disconnects 4 times

1 when host a completes the data transfer, the control bit fin is set to 1 and a request to stop the TCP connection is made
2 Host B responds to the FIN after it receives it, confirming that the TCP connection to the side is closed and the ACK is set to 1
3 by the B-end and then forward the reverse direction of the closing request, the Fin 1
4 Host a confirms the request of Host B, the ACK is set to 1, and the closing of the double direction closes.
It can be seen from the three handshake and four disconnects of TCP that TCP uses the connection-oriented communication method, which greatly improves the reliability of data communication, and makes the transmitting end
And the receiving end of the data before the formal transmission of the interaction, for the formal transmission of data to lay a reliable foundation
noun explanation
ACK one of the control bits of the TCP header to confirm the data. Confirm that the destination is issued, and use it to tell the sender that the data segment before the serial number
All received. For example, the confirmation number is x, that is, the first X-1 data segment received, only when ack=1, the confirmation number is valid, when ack=0, the confirmation number is invalid, this will require retransmission of data, to ensure the integrity of the data.
SYN Synchronous serial number, TCP establishes this position 1 when establishing a connection
The FIN sender completes the send task bit, and when TCP completes the data transfer needs to disconnect, the side that proposes the disconnection will have this position 1
The Baotou structure of TCP:
Source Port 16-bit
Destination Port 16-bit
Serial Number 32 bits
Response Number 32 bit
TCP Header Length 4 bits
Reserved 6-bit
Control Code 6 Bits
Window size 16 bits
Offset 16 bits
Checksum 16-bit
Option 32-bit (optional)
This gives us the minimum length of the TCP header, which is 20 bytes.

UDP (User data Protocol, Subscriber Datagram Protocol)
(1) UDP is a non-connected protocol that transmits data before the source and terminal do not establish a connection, when it wants to transfer the simple to crawl data from the application, and throw it to the network as soon as possible. On the sending side, UDP transmits data at a speed that is limited by the speed of the application-generated data, the ability of the computer, and the transmission bandwidth; At the receiving end, UDP places each message segment in the queue and the application reads a message segment from the queue each time.
(2) Because the transfer data does not establish a connection, so there is no need to maintain the connection state, including the sending and receiving status, so a server can simultaneously transmit the same message to multiple clients.
(3) The header of the UDP packet is very short, with only 8 bytes, and the extra overhead of 20 byte packets relative to TCP is small.
(4) Throughput is not regulated by congestion control algorithms, only the rate of data generated by the application software, the transmission bandwidth, the source side and the performance limit of the terminal host.
(5) UDP uses the best effort to deliver, that is, does not guarantee reliable delivery, so the host does not need to maintain a complex link state table (there are many parameters).
(6) UDP is message-oriented. The sender's UDP message to the application is delivered down to the IP layer after the header is added. Instead of splitting and merging, the boundaries of these messages are preserved, so the application needs to select the appropriate message size.
We often use the "ping" command to test the TCP/IP communication between the two hosts is normal, in fact, the principle of "ping" command is to send UDP packets to the other host, and then the other host to confirm the receipt of the packet, if the packet arrives timely feedback back, then the network is through.
Header structure of UDP:
Source Port 16-bit
Destination Port 16-bit
Length 16 bit
Checksum 16-bit

Summary of the differences between TCP and UDP:
1. Based on connection and no connection;
2. Requirements for system resources (more TCP, less UDP);
3.UDP program structure is relatively simple;
4. Flow mode and datagram mode;
5.TCP guarantees data correctness, UDP may drop packets, TCP guarantees data order, UDP is not guaranteed.

The difference between TCP protocol and UDP Protocol (RPM)

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.