In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is about the differences between tcp and udp. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.
The differences between tcp and udp are as follows: 1. Udp is connectionless, tcp is connection-oriented; 2, udp is unreliable transmission, tcp is reliable transmission; 3. Udp is message-oriented transmission, tcp is byte stream-oriented transmission.
Contrast:
UDP
The full name of UDP protocol is user Datagram protocol. It is a connectionless protocol, which is used to process data packets like TCP protocol in the network. In the OSI model, the fourth layer, the transport layer, is in the upper layer of the IP protocol. UDP does not provide packet grouping, assembly and sorting of packets, that is to say, when a message is sent, it is impossible to know whether it arrives safely and completely.
It has the following characteristics:
1. Connectionless oriented
First of all, UDP does not need to make a three-way handshake to establish a connection before sending data as TCP does. If you want to send data, you can start sending data. And it is only the porter of the data message, will not carry on any split and splicing operation to the data message.
Specifically, it is:
At the sending end, the application layer passes the data to the UDP protocol of the transport layer. UDP will only add a UDP header to the data, which is identified as the UDP protocol, and then passed to the network layer. At the receiving end, the network layer passes the data to the transport layer, and UDP only removes the IP header and passes it to the application layer without any splicing operation.
2. It has the functions of unicast, multicast and broadcast.
UDP not only supports one-to-one transmission, but also supports one-to-many, many-to-many, many-to-one, that is to say, UDP provides unicast, multicast and broadcast functions.
3. UDP is message-oriented
The sender's UDP delivers the message to the application after adding the header and then delivers the IP layer down. UDP neither merges nor splits the messages handed in by the application layer, but retains the boundaries of these messages. Therefore, the application must choose a message of the right size
4. Unreliability
First of all, unreliability is reflected in no connection, communication does not need to establish a connection, want to send, this situation is definitely not reliable.
And the data will be transmitted as soon as it is received, and the data will not be backed up, and the sending data will not care whether the other party has received the data correctly.
In addition, the network environment is good and bad, but because there is no congestion control, UDP will always send data at a constant speed. Even if the network conditions are not good, the transmission rate will not be adjusted. The disadvantage of this implementation is that it may lead to packet loss in the case of poor network conditions, but the advantage is also obvious, in some real-time scenarios (such as teleconference), we need to use UDP instead of TCP.
5. The overhead of the header is small, and it is very efficient to transmit data packets.
TCP
When one computer wants to communicate with another computer, the communication between the two computers needs to be smooth and reliable in order to ensure the correct sending and receiving of data. For example, when you want to view a web page or email, you want to view the web page in its entirety and in order without losing anything. When you download a file, you want to get the complete file, not just part of the file, because if the data is lost or out of order, it is not the result you want, so you use TCP.
The full name of TCP protocol is transmission control protocol, which is a connection-oriented, reliable, byte-stream-based transport layer communication protocol, defined by RFC 793of IETF. TCP is a connection-oriented and reliable streaming protocol. Flow is an uninterrupted data structure, which you can think of as water flow in a drain.
1. TCP connection process
First handshake
The client sends a connection request message segment to the server. The newspaper paragraph contains its own initial serial number of data communication. After the request is sent, the client enters the SYN-SENT state.
The second handshake
After the server receives the connection request message segment, if it agrees to the connection, it will send a reply, which will also contain its own initial sequence number of data communication, and then enter the SYN-RECEIVED state after sending.
The third handshake
When the client receives the reply of the connection consent, it also sends a confirmation message to the server. After sending this message segment, the client enters the ESTABLISHED state, and the server also enters the ESTABLISHED state after receiving this reply, and the connection is established successfully.
Here you may be wondering: why does TCP need three handshakes instead of two to establish a connection? This is because this is to prevent invalid connection request message segments from being received by the server, resulting in an error.
2. TCP breaks the link
TCP is full-duplex, and both sides need to send FIN and ACK when disconnected.
First handshake
If client A thinks that the data is sent, it needs to send a connection release request to server B.
The second handshake
After receiving the request to release the connection, B will tell the application layer to release the TCP link. The ACK packet is then sent and enters the CLOSE_WAIT state, indicating that the connection from A to B has been released and no longer receives the data sent by A. But because the TCP connection is bi-directional, B can still send data to A.
The third handshake
B will continue to send unfinished data at this time, and then send a connection release request to A, and then B will enter the LAST-ACK status.
The fourth handshake
After A receives the release request, it sends a confirmation reply to B. at this time, An enters the TIME-WAIT state. This state lasts for the 2MSL (maximum lifetime, which refers to the time for the message segment to survive in the network, and the timeout will be discarded). If there is no retransmission request from B within this period, it will enter the CLOSED state. When B receives the confirmation reply, it also enters the CLOSED state.
3. The characteristics of TCP protocol
Connection oriented
Connection-oriented means that a connection must be established at both ends before sending data. The way to establish a connection is a "three-way handshake", which makes a reliable connection. The establishment of a connection lays a foundation for reliable data transmission.
Only unicast transmission is supported
Each TCP transmission connection can only have two endpoints, can only carry out point-to-point data transmission, and does not support multicast and broadcast transmission.
Byte flow oriented
Unlike UDP, TCP does not transmit individual messages independently, but in byte stream mode without retaining the message boundary.
Reliable transmission
For reliable transmission, packet loss is judged by the segment number and confirmation number of the TCP. In order to ensure the reliability of message transmission, TCP gives each packet a sequence number. At the same time, the sequence number also ensures the sequential reception of packets transmitted to the receiving entity. Then the receiver entity sends back a corresponding acknowledgment (ACK) for the bytes that have been successfully received; if the sender entity does not receive an acknowledgement within a reasonable round-trip delay (RTT), then the corresponding data (assuming it is lost) will be retransmitted.
Provide congestion control
When the network is congested, TCP can reduce the rate and amount of data injected into the network and alleviate the congestion.
TCP provides full-duplex communication
TCP allows applications on both sides of the communication to send data at any time, because both ends of the TCP connection are cached for temporary storage of data for two-way communication. Of course, TCP can send a segment immediately, or it can cache for a period of time to send more segments at a time (the maximum segment size depends on MSS)
Thank you for reading! What are the differences between tcp and udp to share here, I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 262
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.