Similarities and differences between UDP connections and TCP connections

Simply put, the difference between TCP and UDP is whether there is a connection state.
TCP has a connection state, but UDP does not, so TCP is a relatively secure communication protocol, while UDP is more convenient

 

TCP 127.0.0.1:1026 0.0.0.0:0 LISTENING 
TCP is the transport protocol TCP is the active connection to the web page or something using TCP (seemingly)
UDP is also the transport protocol UDP roundabout connection QQ uses UDP (seemingly)
127.0.0.1 is the local loopback address 
1026 Is the port 
LISTENING is listening on 

TCP 127.0.0.1:1026 0.0.0.0:0 LISTENING 
means listening on TCP 1026 port 
0.0.0.0 is nothing zero 
port 0 is nothing. . . ING

 

TCP is connection-oriented,
UDP is connectionless, and

that is the relationship.


TCP (Transmission Control Protocol, Transmission Control Protocol)
UDP (User Datagram Protocol, User Datagram Protocol)
When an IP packet transmits data to a destination through routing, Different applications will be requested and obtained according to the source port and destination port information in the TCP or UDP header. That is to say, both TCP and UDP contain the necessary source port and destination port information for network services to establish and implement network transmission services. At this time, your question comes: since they are all used for transmission, why do you need to engage in two different protocols? This needs to start from the needs of different services in the network. 

In the network, some services, such as HTTP, FTP, etc., have high requirements on the reliability of data. When using these services, it is necessary to ensure that the data packets can be delivered without errors; while other services, such as DNS, instant chat tools etc., do not need such high reliability, high efficiency and real-time are what they care about. According to the different needs of these two services, the connection-oriented TCP protocol and the connectionless UDP protocol were born. 

The connection (Connection) and connectionless (Connectionless) here are commonly used terms in network transmission, and their relationship can be illustrated by a vivid analogy, that is, making a phone call and writing a letter. 

When making a phone call, a person must first dial (issue a connection request), wait for the other party to respond, answer the call (establish a connection), and then be able to communicate information to each other. After the call is completed, you also need to hang up (disconnect) to complete the entire call process. Writing a letter is different. You only need to fill in the address information of the recipient, then drop the letter into the post office, and the task is completed. At this time, the post office will deliver the letter to the designated destination according to the address information of the recipient. 

As we can see, there is a big difference between the two. When making a phone call, both parties to the call must establish a connection in order to transmit information. Connections also ensure the reliability of information transfer, so connection-oriented protocols must be reliable. There is not so much emphasis on connectionless. It does not matter whether the other party responds or has feedback, it just sends the information. Just like once a letter has entered the mailbox, you cannot track the whereabouts of the letter until it reaches its destination; even if the recipient receives the letter, it will not notify you when the letter has arrived. There are no guarantees during the entire communication process. Therefore, we often say that connectionless-oriented protocols are also unreliable. Of course, the post office will do its best to deliver the right key to the destination, and 99% of the time the letter will arrive safely, but there are a few exceptions. 

The connection-oriented protocol has a significant advantage in reliability over the connectionless protocol, but it must wait for the receiver to respond before establishing a connection. During the transmission of information, it must be confirmed whether the information has been transmitted, and a response signal needs to be sent when the connection is disconnected. Invisibly increases the resource overhead of the connection-oriented protocol. Specifically for the TCP and UDP protocols, in addition to the source port and destination port, TCP also includes sequence numbers, acknowledgment signals, data offsets, control flags (usually URG, ACK, PSH, RST, SYN, FIN), window, calibration Checksum, urgent pointer, options and other information, UDP only contains length and checksum information. UDP datagrams are much smaller than TCP, which means less load and more efficient use of bandwidth. Many instant chat software use UDP protocol, which has a great relationship with this.

 

TCP---Transmission Control Protocol, provides connection-oriented, reliable byte stream service. When a client and a server exchange data with each other, a TCP connection must be established between the two parties before data can be transmitted. TCP provides functions such as timeout retransmission, discarding duplicate data, checking data, and flow control to ensure that data can be transmitted from one end to the other. UDP---User Datagram Protocol, is a simple datagram-oriented transport layer protocol. UDP does not provide reliability, it just sends out the datagrams that the application passed to the IP layer, but there is no guarantee that they will reach their destination. Because UDP does not need to establish a connection between the client and the server before transmitting the datagram, and there is no mechanism such as timeout and retransmission, the transmission speed is very fast. Whether to use TCP or UDP, it depends on which aspect your program pays attention to? Reliable or fast?
 
TCP UDP是两个协议,简单的说,TCP连接要对方确认的,而UDP却不需要对方确认收到包,所以TCP连接更加安全,但是一般播放网络流媒体使用UDP协议
 
传输层协议一般有TCP和UDP,TCP为可靠传输,协议本身会保证数据传输的可靠,但为此会付出很多额外的网络开销。UDP为不可靠传输,所以传输效率

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326710635&siteId=291194637