TCP and UDP differences, TCP transmission principle, congestion avoidance, connection establishment, connection release Summary

Source: Internet
Author: User

TCP and UDP are transport-layer protocols that provide logical communication between end-to-end processes, while the IP protocol (Network Layer) provides logical communication between hosts, the protocol that the application layer requires for communication.

1. Main Features of UDP: User Datagram Protocol is transmitted.

1. UDP is connectionless, that is, no connection is required before sending data.

2. UDP uses the best effort to deliver, that is, reliable delivery is not guaranteed, and congestion control is not used.

3. UDP is packet oriented. UDP has no congestion control and is suitable for multimedia communication.

4. UDP supports one-to-one, one-to-many, one-to-one, and many-to-many interactive communication.

5. The UDP header has a low overhead of 8 bytes.

The packet sent by the sender UDP to the application is delivered to the IP layer after the header is added. UDP does not merge or split packets handed over to the application layer, but retains the boundaries of these packets. The maximum number of packets sent from the application layer to UDP. UDP sends one packet at a time. The UDP User Datagram sent by the receiver to the IP layer is delivered to the upper-layer application process intact after the header is removed, delivering a complete packet at a time.

The application must select the appropriate packet size. Ii. Main Features of TCP: 1.tcp is a connection-oriented transport layer protocol. 2. Each TCP connection can have only two endpoints, and each TCP connection can only be point-to-point (one-to-one ). 3. TCP provides reliable delivery services. 4. TCP provides full-duplex communication. 5. TCP is for byte streams. 6. The minimum length of the header is 20 bytes. Working principle of TCP reliable transmission: Stop the waiting protocol (confirm retransmission mechanism) 1. no error: 1>: no error: Send group M1 of A. Send the message to suspend sending. wait for confirmation from B, and send confirmation to a upon receiving M1, A receives the M1 confirmation and sends it to the next group. 2>: an error occurs. If a does not receive the confirmation after a period of time, the Group sent is lost, the Group sent before retransmission is called timeout retransmission. Implemented by the retransmission timer. And: (1) a must retain the group copy for each send group; (2) the group and confirm group must be numbered '(3) the retransmission time of the timeout timer should be more than the average round-trip time of the data in the group. 3>: If B receives the repeated group M1, it does not want to deliver it on the previous layer. Besides, send a confirmation message to.
2. Timeout retransmission: the advantage of the Stop wait protocol is that it is simple, but the channel utilization is too low. The solution is to adopt the continuous ARQ protocol. The sender maintains the sending window and sends several groups consecutively each time. The receiver uses the cumulative confirmation to send confirmation to the last group that arrives in order. The disadvantage is that it cannot reflect to the sender all the group information that the receiver has correctly received, such as the loss of the intermediate group.

Implementation of TCP reliable transmission:
Each end of a TCP connection must have two windows: one sending window and one receiving window. The reliable transmission mechanism of TCP is controlled by the serial number of bytes. All TCP validation is based on serial numbers rather than Packet segments. The sent data must be retained before being confirmed, so that it can be used for time-out re-transmission. The sending cache is used to temporarily store the data that the sending application sends to the sender TCP for sending when the sending window does not change (no confirmation is received) and Forward (New confirmation is received; TCP has sent data but has not received confirmation. The receiving cache is used for temporary storage: data that arrives in order but has not been read by the receiving application; data that does not arrive in order. Three points must be emphasized: 1> A's sending window is not always as big as B's receiving window (because of a certain time lag ). 2> the TCP standard does not specify how data that does not arrive in order should be processed. Generally, it is first temporarily stored in the receiving window, and then delivered to the upper-layer application process in order after the missing bytes in the byte stream are received. 3> TCP requires the receiver to have a cumulative validation function, which can reduce the transmission overhead.

TCP traffic control:
Flow Control is to prevent the sender from sending speed too fast, so that the receiver can receive it in time and avoid network congestion. The sliding window mechanism can be used to conveniently control traffic over TCP connections. TCP provides a continuous timer for each connection. As long as the TCP connection party receives the zero-window notification from the other party, it starts the continuous timer and sends a zero-window detection packet segment.
TCP congestion control: in a certain period of time, if the demand for a certain resource on the network exceeds the available part of the resource, the network performance will deteriorate-resulting in congestion (congestion ). Condition for resource congestion: Sum of resource requirements> available resources. The open-loop control method is to consider the congestion factors carefully before designing the current affairs of the network, and strive to avoid network congestion during work. Closed-loop control is based on the concept of feedback loop. Closed-loop control includes the following measures: monitoring the network system to detect when and where congestion occurs. Transmits congested information to a place where action can be taken. Adjust the running of the network system to solve the problem. Congestion Control Method: 1. Slow Start: when the host just starts to send the packet segment, you can set the congestion window cwnd to a maximum message segment MSS value. After receiving a confirmation message segment, the congestion window is increased to one MSS value. Gradually increasing the congestion window cwnd at the sending end using this method can make the packet injection rate to the network more reasonable. Every time a transmission cycle occurs, the congestion window (sender) doubles. 2. Congestion avoidance: increases the congestion window slowly, and increases by 1 for every round-trip time, instead of doubling, and increases slowly according to the linear law. When the congestion window is greater than the start threshold, the congestion avoidance algorithm is executed. "Multiplication reduces": whether in the slow start or congestion avoidance phase, the slow start threshold is halved as long as timeout retransmission occurs. "Plus points increase": After the algorithm is executed to avoid congestion, the congestion window increases slowly to prevent premature network congestion. It is called the AIMD algorithm. 3. Fast retransmission algorithm: as long as the sender receives three repeated confirmations in a row, it should re-transmit the packets not received by the other party. You do not have to wait until the retransmission timer of this group expires. 4. fast recovery algorithm: (1) when the sending end receives three consecutive repeated confirmations, it executes the multiplication and reduction algorithm to halved the slow start threshold ssthresh. However, the slow start algorithm is not executed. (2) because the sender thinks that the network is likely not congested, the slow start algorithm is not executed, that is, the congestion window cwnd is not set to 1 now, instead, it is set to the value after the ssthresh threshold is halved, and then the congestion avoidance algorithm ("addition increases") is executed to linearly increase the congestion window slowly.
TCP transportation establishment: the customer server is used to actively initiate the establishment of the customer, and the application process passively waiting for the establishment of the connection is the server. 1. tcp of a sends a connection request packet segment to B, and the synchronization bit SYN in the header is 1, and the sequence number seq = X, indicates that the sequence number of the First Data byte during data transmission is X. 2. After TCP of B receives the connection request packet segment, if it is agreed, it will be sent back for confirmation. B should enable SYN = 1 in the validation packet segment and ACK = 1, its confirmation number ACK = x + 1, and its own sequence number seq = y. 3. After receiving the packet segment, a will confirm with B. ACK = 1 and ACK = Y + 1. A tcp notifies the upper-layer application process that the connection has been established. 4. After receiving confirmation from host a, TCP of host B also notifies its upper-layer application process that the TCP connection has been established.

TCP connection release
1. After data transmission ends, both parties can release the connection. Now, the application process of a first releases the packet segment from its TCP connection, stops sending data, and closes the TCP connection. A releases the fin of the first part of the packet segment with the serial number seq = u, waiting for B's confirmation. 2. B sends a confirmation message, ACK = u + 1, and the serial number of this segment is seq = v. The TCP server process notifies the high-level application process. The connection from A to B is released, and the TCP connection is semi-closed. If B sends data, a still needs to receive it. 3. If B has no data to send to a, its application process notifies TCP to release the connection, and the connection from B to A is also released. 4. after receiving the connection release packet segment, a must send a confirmation. In the confirmation packet segment, ACK = 1, ACK = W + 1, your serial number seq = u + 15.tcp connection must be released after 2msl. Because: to ensure that the last ACK packet segment sent by a can reach B, the "invalid connection request packet segment" is prevented from appearing in this connection. After sending the last ACK packet segment and then passing through the time 2msl (time Wait timer), a can make all the packet segments generated during the connection duration, all disappears from the network. In this way, the old connection request packet segment will not appear in the next new connection.
Organic status chart: There are three different arrows in the diagram. The solid line arrow indicates normal changes to the customer process. The bold dotted line arrows indicate normal changes to server processes. Another thin arrow indicates abnormal changes.


TCP and UDP differences, TCP transmission principle, congestion avoidance, connection establishment, connection release Summary

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.