TCPthe difference between protocol and UDP protocol
first, let's get this straight.TCPagreements andUCPAgreement andTCP/IPagreement, a lot of people are confused, has always been saidTCP/IPAgreement andUDPthe difference between the protocols, I think it is not clear from the nature of network communication!
TCP/IPthe 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.
Tcp / ipThe protocol set includes the application layer, the Transport layer,Network layer,Network access Layer。
whichThe application layer includes:
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
InternetHost, 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.
SecondlyNetwork layerIncluding:
InternetProtocol (IP)
InternetControl Information Protocol (ICMP)
Address Resolution Protocol (ARP)
Reverse Address Resolution Protocol (RARP)
Finally saidNetwork access layer: The network access layer is also known as the host-to-network layer (host-to-network). The capabilities of the network access layer include the mapping of IP addresses to physical address hardware, and the encapsulation of 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'm not quite perfect here.Tcp / ipAgreementis a science, each branch is a very complex process, but I believe that every student learning software development needs to be carefully understood.
I'll focus on the followingTCPagreements andUDPthe 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 times.“Dialogue”In order to build up, the process is very complex, and simply describes the simple process of the three conversations: Host A sends a connection request packet to Host B:“I want to send you the 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 sending, one in the receiving, coordinating work) packet:“Yes, when are you going to send it?”, this is the second conversation; Host a then sends a packet to confirm that Host B requires synchronization:“I'll send it now, and you go ahead!”, this is the third dialogue. three times“Dialogue”The purpose is to synchronize the sending and receiving of packets, after three times“Dialogue”After that, host a formally sends data to Host B.
In detail, it is:(Part of the article reprinted http://zhangjiangxing-gmail-com.iteye.com, mainly this person explained very in place, indeed very easy to make people understand! )
TCPthree-time handshake process
1Host A is sent to host B by sending a data segment containing a flag bit of the synchronization sequence number to Host B, which is requested to establish a connection to host B, through which the 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
TCP3 handshake to make connection, 4 times for disconnection
1When 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
AckTcpOne of the control bits of the header to confirm the data. Confirm that the destination is emitted, 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.
SynSynchronize serial number, TCP establishes this position 1 when connection is established
FINThe 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
TCPthe 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 usagedo 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 isMessage 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 ping " command to test whether TCP/IP communication between the two hosts is normal, in fact ping " udp Baotou structure:
source port 16-bit
Destination port 16-bit
Length 16-bit
Checksum 16-bit
Summary the difference between TCP and UDP:
1. based on connection and no connection;
2. Requirements for system resources (TCP more, UDP less);
3.UDP program structure is simpler;
4. Stream mode and datagram mode;
5.tcp< Span style= "color:black;" > guaranteed data correctness, UDP may drop packets, TCP guarantees data order, UDP is not guaranteed.
Differences between TCP and UDP (RPM)