Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction to TCP and UDP

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "introduction of TCP and UDP". In daily operation, I believe many people have doubts about the introduction of TCP and UDP. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "introduction of TCP and UDP"! Next, please follow the editor to study!

What is TCP/IP?

For computers and network devices to communicate with each other, both sides must be based on the same method. For example, rules such as how to detect the communication target, which side initiates the communication, which language to use for communication, and how to end the communication need to be determined in advance. Communication between different hardware and operating systems, all of which requires a rule. We call this rule protocol.

TCP/IP is the general name of all kinds of protocols related to the Internet, such as TCP,UDP,IP,FTP,HTTP,ICMP,SMTP, which belongs to the TCP/IP family. Putting together the protocols associated with the Internet like this is always called TCP/IP. It is also said that TCP/IP refers to the two protocols TCP and IP. There is also a saying that TCP/IP is the general name of the protocol family used in the communication process of the IP protocol.

-

Original link: https://blog.csdn.net/chaoshenzhaoxichao/article/details/79785318

I. definition

TCP: transmission Control Protocol (Transmission Control Protocol) is a connection-oriented, reliable, byte-stream-based transport layer communication protocol

UDP: user Datagram Protocol (User Datagram Protocol), is a simple Datagram-oriented transport layer protocol

TCP shaking hands and waving hands

The so-called three-way handshake (Three-Way Handshake) is the establishment of a TCP connection, which means that when establishing a TCP connection, the client and server need to send a total of three packets to confirm the establishment of the connection. In socket programming, this process is triggered by the client executing connect, as shown in the following figure:

(1) first handshake: Client sets the flag bit SYN to 1, randomly generates a value of seq=J, and sends the packet to Server,Client to enter the SYN_SENT state, waiting for Server to confirm.

(2) second handshake: after the Server receives the packet, the flag bit SYN=1 knows that the Client requests to establish a connection. Server sets the flag bits SYN and ACK to 1 seq=K, randomly generates a value seq=K, and sends the packet to Client to confirm the connection request, and the Server enters the SYN_RCVD state.

(3) the third handshake: after receiving the confirmation, Client checks whether the ack is Jacks 1, if the flag bit ACK is set to 1, and sends the packet to Server,Server to check whether the ack is 1. If it is correct, the connection is established successfully, Client and Server enter the ESTABLISHED state, and the three-way handshake is completed, and then data transmission can begin between Client and Server.

The so-called four-wave (Four-Way Wavehand) terminates the TCP connection, which means that when a TCP connection is disconnected, the client and server need to send a total of 4 packets to confirm the disconnection. In socket programming, this process is triggered by the execution of close by either the client or the server, as shown in the following figure:

The process and status are already clear in the figure above, so I'm not going to repeat them here, but you can refer to the previous four wave parsing steps.

Why does it take three handshakes to establish a connection and four waves to close the connection?

This is because the server in the LISTEN state, after receiving the SYN message of the connection request, sends ACK and SYN to the client in a single message. When you close the connection, when you receive the FIN message from the other party, it only means that the other party can no longer send data but can still receive data, and your own side may not send all the data to the other party, so you can immediately close, or send some data to the other party, and then send a FIN message to the other party to indicate that you agree to close the connection now. Therefore, your ACK and FIN will generally be sent separately.

Summary of the differences between TCP and UDP:

TCP is connection-oriented (for example, dial-up to establish a connection first); UDP is connectionless, that is, no connection needs to be established before data is sent.

TCP provides reliable service. In other words, the data transmitted through the TCP connection is error-free, not lost, not repeated, and arrives in sequence; UDP does its best to deliver, that is, reliable delivery is not guaranteed.

Tcp achieves reliable transmission through checksum, retransmission control, serial number identification, sliding window and acknowledgement response. Such as the retransmission control when the packet is lost, the subpackets that are out of order can also be controlled sequentially.

UDP has better real-time performance and higher working efficiency than TCP, so it is suitable for high-speed transmission and real-time communication or broadcast communication.

Each TCP connection can only be point-to-point; UDP supports one-to-one, one-to-many, many-to-one and many-to-many interactive communications.

TCP requires more system resources, while UDP requires less system resources.

At this point, the study of "introduction to TCP and UDP" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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: 0

*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.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report