The difference between TCP protocol and UDP protocol

Source: Internet
Author: User
Tags file transfer protocol

TCP the difference between protocol and UDP protocol

first, let's get this straight. TCP agreements and UCP Agreement and TCP/IP agreement, a lot of people are confused, has always been said TCP/IP Agreement and UDP the difference between the protocols, I think it is not clear from the nature of network communication! TCP/IP the 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.   Common network Protocols -UDP: The concept comes from "Telegraph" -Just send, not confirm whether the other party received -Sent as a packet, each packet cannot exceed 64K size -Before sending, it is not necessary to confirm whether the receiving party is online -UDP is higher than TCP in terms of delivery efficiency   Current network environment, application scenario: Web classroom, streaming media Video (ts format)   -tcp: -Secure data Transfer Protocol, must ensure the complete transmission of the information successfully -"Three handshake" to ensure that both the sender and receiver of the data are online and capable of transmitting data -Large files can be transferred with no limit on the size of the transmitted files -accuracy of data delivery, TCP is higher than UDP  The TCP/IP protocol set includes the application layer, the transport layer, the network layer, and the network access layer.   The application layer includes: Hypertext Transfer Protocol (HTTP): The basic protocol of the World Wide Web.    File transfer (TFTP Simple File Transfer Protocol): Telnet, provides remote access to other host features, which allows a user to log on to an 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. Next network layer includes: Internet Protocol (IP) Internet Control Information Protocol (ICMP) Address Resolution Protocol (ARP) Reverse Address Resolution Protocol (RARP) finally said the network access layer: The network access layer is also called the host to the network layer (HOST-TO-NETW ORK). The capabilities of the network access layer include the mapping of IP addresses to physical address hardware, as well as the encapsulation of IP into frames. The network access layer defines the connection to the physical media based on the network interfaces of different hardware types. Of course I don't speak well enough here, the TCP/IP protocol is a science, Each branch is a very complex process, but I believe that every student who learns software development needs to have a closer look. I'll focus on the following TCP agreements and UDP the difference between the protocols. 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 it has received the data segment of Host B: "I have received a reply, I am now going to start transmitting the actual data so that 3 times the handshake is complete, 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 3 handshake to make connection, 4 times for disconnection

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 TCP the Baotou structure:

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 usage do your best to deliver,That is, there is no guarantee of reliable delivery, so the host does not need to maintain a complex link state table (which has many parameters). (6) UDP is Message OrientedOf 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. UDP the Baotou structure:

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, and UDP is not guaranteed.

The difference between TCP protocol and UDP protocol

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.