Home  >  Article  >  Web Front-end  >  What is the difference between TCP/IP and UDP?

What is the difference between TCP/IP and UDP?

一个新手
一个新手Original
2017-09-07 13:58:452596browse

TCP (Transmission Control Protocol)

is a connection-oriented protocol, that is to say, before sending and receiving data, it must Establish a reliable connection with the other party. A TCP connection must go through three "conversations" before it can be established

TCPThree-way handshakeProcess:

1 Host A sends a data segment containing the flag bit of the synchronization sequence number to Host B and requests Host B to establish a connection. Through this data segment, Host A tells Host B two things: I want to I want to communicate with you; which sequence number can you use as the starting data segment to respond to me.

2 Host B, after receiving the request from Host A, responds with a confirmation ( The data segment with ACK) and synchronization sequence number (SYN) flags responds to host A and tells host A two things: I have received your request and you can transmit data; which sequence number do you want to use as the starting point? The first data segment to respond to me

3 After host A receives this data segment, it sends a confirmation response to confirm that it has received the data segment from host B: "I have received the reply , I am now going to start transmitting actual data

In this way, the three-way handshake is completed, and host A and host B can transmit data.

Characteristics of the 3-way handshake:

1) No application layer data

2) SYN flag The bit will only be set to 1 when TCP establishes a connection

3) The SYN flag is set to 0 after the handshake is completed

TCP requires 3 handshakes to establish a connection, while requires 4 handshakes to disconnect

##1 When host A completes the data transmission, it will control The FIN bit is set to 1, making a request to stop the TCP connection

2 Host B responds to the FIN after receiving it, confirms that the TCP connection in this direction will be closed, and sets ACK to 1

3 The B-side makes another close request in the opposite direction, sets FIN to 1

4 Host A confirms Host B’s request, sets ACK to 1, and the two-way shutdown ends.

It can be seen from TCP’s three-way handshake and four disconnections that TCP The use of connection-oriented communication greatly improves the reliability of data communication, allowing the sending data end and the receiving end to interact before the data is officially transmitted, laying a reliable foundation for the formal data transmission

Explanation of terms

ACK - One of the control bits in the TCP header, which confirms the data. The confirmation is sent by the destination, and is used to tell The sender has received all the data segments before the sequence number. For example, if the confirmation number is , the confirmation number is invalid, then the data will be required to be retransmitted to ensure the integrity of the data.

SYN——Synchronization sequence number, set this position to 1 when TCP establishes a connection

FIN——The sender has completed the sending task bit. When TCP completes the data transmission and needs to be disconnected, the party that proposes to disconnect will set this bit to 1

TCP header structure:

Source port 16 bits

Destination port 16 bits

Sequence number 32 bits

Response sequence number 32 bits

TCP header length 4 bits

reserved 6 digits

Control code 6 digits

Window size 16 digits

Offset 16 bits

Checksum 16 bits

Option 32 bits (optional)

In this way we get the minimum length of the TCP header, which is 20 bytes.

UDP (User Data Protocol, User Datagram Protocol)

(1) UDP is a non-connection protocol. The source and terminal do not establish a connection before transmitting data. When it wants to transmit, it simply grabs the data from the application and transmits it as quickly as possible. Throw it on the web. On the sending end, the speed at which UDP transmits data is only limited by the speed at which the application generates data, the computer's capabilities, and the transmission bandwidth; at the receiving end, UDP puts each message segment in a queue, and the application reads each message segment from the queue each time. Read a message segment.

(2) Since no connection is established when transmitting data, there is no need to maintain the connection status, including sending and receiving status, etc. Therefore, a server machine can transmit the same data to multiple clients at the same time. news.

(3) The header of the UDP packet is very short, only 8 bytes. Compared with the 20-byte packet of TCP, the additional overhead is very small.

(4) Throughput is not regulated by the congestion control algorithm and is only limited by the rate of data generated by the application software, transmission bandwidth, and source and terminal host performance.

(5) UDP uses best-effort delivery, that is, reliable delivery is not guaranteed, so the host does not need to maintain a complex link state table (there are many parameters in it).

(6) UDP is message-oriented. The message handed over by the sender's UDP to the application program is delivered down to the IP layer after adding a header. Neither splitting nor merging is done, but the boundaries of these packets are preserved, so the application needs to choose an appropriate packet size. We often use the "ping" command to test whether the TCP/IP communication between two hosts is normal. In fact, the principle of the "ping" command is to send a UDP data packet to the other host, and then the other host confirms receipt of the data packet. If the data packet is If the arriving news is fed back in time, the network will be open.

UDP header structure:

##Source port 16 bits

Destination port 16 bits

Length 16 bits

Checksum 16 bits

Summary of the difference between TCP and UDP:

1. Based on connection and connectionless;

2. On system resources Requirements (more TCP, less UDP);

3. UDP program structure is relatively simple;

4. Stream mode and datagram mode ;

5.TCP guarantees data correctness, UDP may lose packets, TCP guarantees data order, but UDP does not.

The above is the detailed content of What is the difference between TCP/IP and UDP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn