The difference between TCP/IP protocol and UDP protocol

Source: Internet
Author: User
Tags ack

Reprint article Source address: http://zhangjiangxing-gmail-com.iteye.com/blog/646880 TCP /IP protocol differs from 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:" Yes, 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. TCP Three-time handshake process host A to host B by sending a data segment containing a flag bit of the synchronization sequence 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. 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
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. three-time handshake features no application layer of Data SYN This flag bit will only be set when the TCP build connection is set 1 The SYN flag bit is set 0 after the handshake is completed

TCP establishes a connection to make 3 handshake, and disconnect to do 4 times when host a sends the data, the fin will be 1, to Host B to request a broken link;
Host A tells the Host B: I have no data to send to you; If you still have data not sent out, do not have to worry about closing, you can send the data first, Host B receives fin response to it, confirm that the TCP connection in this direction will be closed, the ACK is set to 1; Host B tells host A: Your request I received, But not ready, please wait for my message. The counter-direction request is made by the B-terminal, the fin is set 1; Host B tells the host a: I have no data, ready to shut down the connection; Host a request confirmation to Host B, will ack 1, double-direction off
Host A tells the Host B: Know, can be closed, goodbye;

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, so that the transmitting data end and the receiving end have interaction before the formal transmission of the date, which lays a reliable foundation for the formal transmission of data.

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 be disconnected, the side that proposes the disconnection will be 1 why the connection requires three handshake, and the disconnection requires four waves

When the connection request is received, the server can directly respond to the syn+ack at the same time, when the shutdown request is received, because it is not sure that the data has been sent, so the first response to the client, and then determine whether the data is sent, and then confirm that it can be closed to the client, it is four times waved; The Baotou structure of TCP


Source Port 16-bit destination port 16-bit serial number 32-bit response ordinal 32-bit TCP header length 4-bit reserved 6-bit control Code 6-bit window size 16-bit offset 16-bit check and 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) UDP is a non-connected protocol that transmits data before the source and terminal do not establish a connection, and when it wants to teleport, it simply crawls data from the application and throws it to the network as quickly 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. Since the transfer data does not establish a connection, there is no need to maintain the connection state, including sending and receiving status, so a server can transmit the same message to multiple clients at the same time. The header of a UDP packet is short, with only 8 bytes, and the extra overhead of a 20-byte packet relative to TCP is minimal. Throughput is not regulated by congestion control algorithms and is limited only by the rate of data generated by the application software, transmission bandwidth, source side, and terminal host performance. UDP uses its best effort to deliver, i.e. it does not guarantee reliable delivery, so the host does not need to maintain a complex link state table (which has many parameters). 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. UDP Header Structure source port 16-bit destination port 16-bit length 16-bit checksum 16-bit Summary The difference between TCP and UDP is based on connection and no connection, the requirements of system resources (TCP more, UDP less), UDP program structure is simpler;
Stream mode and datagram mode, TCP guarantees data correctness, UDP may drop packets, TCP guarantees data order, UDP is not guaranteed. Reference Articles

http://blog.csdn.net/whuslei/article/details/6667471/
http://swiftlet.net/archives/1082
/http/ www.cnblogs.com/bizhu/archive/2012/05/12/2497493.html

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.