The difference of the tcp&udp of "Unity3d self-study record" network programming

Source: Internet
Author: User
TCP (Transmission Control Protocol, Transmission Control Protocol) is a connection based agreement, that is, a reliable connection must be established with the other before the data is officially sent and received. A TCP connection must go through three "conversations" to build up, the process is very complex, we only do a simple, image of the introduction, you can only understand this process can be. Let's take a look at the simple process of these three conversations: Host A sends a connection request packet to Host B: "I want to send you the data, OK." "This is the first conversation; Host B sends a consent connection to host A and requires synchronization (sync is two hosts one in the sending, one in receiving, coordinating work) of the packet:" Yes, when you send it. " "This is the second conversation; Host a again sends a packet confirming Host B's request synchronization:" I'll send it now. "This is the third dialogue. Three times the purpose of "dialogue" is to synchronize the sending and receiving of packets, after three "conversations", host a does not officially send data to Host B.


UDP (User data Protocol, Subscriber Datagram Protocol) is a protocol corresponding to TCP. It is a connectionless protocol that does not establish a connection with the other, but instead sends the packet to the past directly. UDP is suitable for applications where only a small amount of data is transmitted at a time and the reliability requirements are not high. For example, we often use the "ping" command to test the normal TCP/IP communication between the two hosts, in fact, the "ping" command is to send UDP packets to the other host, and then the other host to confirm the receipt of packets, if the packet arrived at the news timely feedback back, then the network is through. For example, in the default state, a "ping" operation sends 4 packets (as shown in Figure 2). You can see that the number of packets sent is 4 packets, received is also 4 packets (because the other host received after the receipt will send a confirmation of the packet received). This fully demonstrates that the UDP protocol is a connectionless protocol and that there is no process to establish a connection. Because the UDP protocol is not connected, its communication effect is high, but because of this, its reliability is not as high as the TCP protocol. QQ uses UDP to send messages, so there are times when messages are not received.


The two explanations for TCP and UDP are straightforward.

In fact, the difference between TCP and UDP is still obvious

TCP is connected, and UDP is connectionless

TCP transmission is reliable and is unreliable relative to UDP

TCP is used to transmit large amounts of data, while UDP is suitable for small amounts of data

The last and most important thing is that TCP is slow, and relatively fast for UDP.

Please feel free to tell me any questions so that I can correct them in time. Thank you for your support.

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.