What is the difference between TCP and UDP protocols
Nowadays, the popular protocol on the Internet is TCP/IP protocol, which has an exact definition of ports below 1024, and they correspond to some common services on the Internet. Below I'll share with you some of the differences between TCP and UDP protocols, welcome!
I. Introduction to the TCP protocol
TCP (Transmission Control Protocol) is a connection-oriented protocol, that is to say, before sending and receiving data, it is necessary to establish a reliable connection with each other.
A TCP connection must go through three ? conversations? to be established, which is a very complex process, only a simple description of the simple process of these three conversations: host A to host B to send a connection request packet: ? I want to send you data, can I? This is the first conversation; Host B sends Host A a packet agreeing to connect and requesting synchronization (synchronization means that the two hosts are working in coordination, one sending and one receiving): ? Yes, when will you send it? This is the second conversation; Host A sends another packet to confirm Host B's request for synchronization: ? I'll send it now, go ahead! This is the third conversation. This is the third conversation. dialog? The purpose of the three conversations is to synchronize the sending and receiving of data packets. dialog? After that, host A sends data formally to host B.
The three handshakes of TCP are as follows:
1. Host A requests a connection from host B by sending host B a data segment containing a flag bit with a synchronization sequence number, through which host A tells host B two things: I want to communicate with you; and which sequence number you can respond to me by using as the starting data segment.
2. Host B receives Host A's request and responds to Host A with a data segment with an acknowledgement (ACK) and a synchronization sequence number (SYN) flag bit, which also tells Host A two things: I've received your request and you can transmit data; and which sequence number you want to respond to me with as the starting data segment.
3. After host A receives this data segment, it sends another acknowledgement response confirming that it has received host B's data segment: ? I have received the reply and I will now start transmitting the actual data. This completes the 3 handshakes, and Host A and Host B are ready to transmit data.
TCP takes 3 handshakes to establish a connection and 4 to disconnect.
1. When host A finishes transmitting data, it sets the control bit FIN to 1, and makes a request to stop the TCP connection;
2. Host B receives FIN and responds to it, confirming that the TCP connection will be closed in this direction, by setting ACK to 1;
3. Host B makes a request to close in the opposite direction by setting FIN to 1;
4. Host A responds to host B's request to close in the opposite direction, by setting FIN to 1;
5. Host A makes a request to host B's request to close in the opposite direction. > 4. Host A acknowledges host B's request, sets ACK to 1, and the two-way shutdown ends.
By TCP's three handshakes and four disconnections, it can be seen that TCP uses connection-oriented communication to greatly improve the reliability of data communication, so that the sender and receiver of data have interacted with each other before the data is formally transmitted, which provides a reliable foundation for the formal transmission of data.
Second, the UDP protocol introduction
UDP (User Data Protocol)? User Datagram Protocol, a simple datagram-oriented transport layer protocol.UDP does not provide reliability; it simply sends datagrams passed to the IP layer by an application, but there is no guarantee that they will reach their destination. Because UDP does not establish a connection between the client and the server before transmitting datagrams, and because there are no mechanisms such as timeout retransmissions, it is very fast.
The UDP protocol has the following characteristics:
(1) UDP is a non-connecting protocol that transmits data without establishing a connection between the source and the endpoint before transmitting it, and when it wants to transmit it simply goes and grabs the data from the application program and throws it onto the network as fast as possible. On the sending side, the speed at which UDP transmits data is limited only by the speed at which the application generates the data, the capabilities of the computer, and the transmission bandwidth; on the receiving side, UDP puts each message segment on a queue, and the application reads one message segment at a time from the queue.
(2) Since no connection is established for transmitting data, there is no need to maintain the connection state, including the send/receive state, etc., so a server can transmit the same message to multiple clients at the same time.
(3) UDP message packets have a short header of 8 bytes, which has very little additional overhead compared to TCP's 20-byte message packets.
(4) Throughput is not regulated by congestion control algorithms and is limited only by the rate at which the application software generates data, the transmission bandwidth, and the performance of the source and end hosts.
(5) UDP uses best-effort delivery, i.e., reliable delivery is not guaranteed, so hosts do not need to maintain complex `link state tables (which have many parameters).
(6) UDP is message-oriented. The sender's UDP pairs of messages handed down by the application are delivered down to the IP layer after the first part is added. Neither splitting nor merging is done, but rather the boundaries of these messages are preserved, so the application needs to choose the right message size.
We often use the ?ping? command to test whether TCP/IP communication between two hosts is normal, in fact, the principle of the ?ping? command is to send a UDP packet to the other host, and then the other host to confirm receipt of the packet, if the packet is whether the arrival of the message back in a timely manner, then the network is through.
Third, the difference between TCP and UDP summary
1. TCP-oriented connection (such as phone calls to dial to establish a connection); UDP is connectionless, that is, no need to establish a connection before sending the data;
2. TCP provides a reliable service. That is, data transmitted over a TCP connection arrives without error, loss, or duplication, and in sequence; UDP delivers to the best of its ability, but does not guarantee reliable delivery;
3. TCP is byte-stream oriented, which is actually TCP's way of looking at the data as an unstructured series of byte streams; UDP is packet oriented;
4. UDP does not have congestion control, so network congestion does not reduce the sending rate of the source host (useful for real-time applications such as IP telephony, real-time videoconferencing, etc.);
5. each TCP connection can only be point-to-point; UDP supports one-to-one, one-to-many, many-to-one, and many-to-many interactions;
6. the first part of the overhead of TCP is 20 bytes; the first part of UDP has a small overhead of 8 bytes;
6. the first part of TCP is 20 bytes; UDP's first part is 8 bytes
7. The logical communication channel of TCP is a full-duplex reliable channel, while UDP is an unreliable channel.
Four applications
UDP is used in situations where TCP's reliability mechanisms are not required, for example, when a higher-level protocol or application provides error and flow control functions. UDP is a transport layer protocol that serves many well-known application layer protocols, including Network File System (NFS), Simple Network Management Protocol ( SNMP), Domain Name System (DNS), and the Simple File Transfer System (TFTP). For example, in daily life, common applications that use the UDP protocol are as follows: QQ Voice, QQ Video, TFTP ?
TCP is a connection-oriented, reliable, byte-stream-based transport layer communication protocol, often described by RFC 793 of the IETF. In the simplified OSI model of computer networking, it accomplishes the functions specified by the transport layer. Some of the more demanding services generally use this protocol, such as FTP, Telnet, SMTP, HTTP, POP3, and so on.
;