TCP vs UDP

Posted anyu686

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TCP vs UDP相关的知识,希望对你有一定的参考价值。

Connection

TCP is a connection-oriented protocol. UDP is a connectionless protocol.
Function As a message makes its way across the internetfrom one computer to another. This is connection based. UDP is also a protocol used in message transport or transfer. This is not connection based which means that one program can send a load of packets to another and that would be the end of the relationship.
Usage TCP is suited for applications that require high reliability, and transmission time is relatively less critical. UDP is suitable for applications that need fast, efficient transmission, such as games. UDP‘s stateless nature is also useful for servers that answer small queries from huge numbers of clients.
Use by other protocols HTTP, HTTPs, FTP, SMTP, Telnet DNS, DHCP, TFTP, SNMP, RIP, VOIP.
Ordering of data packets TCP rearranges datapackets in the order specified. UDP has no inherent order as all packets are independent of each other. If ordering is required, it has to be managed by the application layer.
Speed of transfer The speed for TCP is slower than UDP. UDP is faster because error recovery is not attempted. It is a "best effort" protocol.
Reliability There is absolute guarantee that the data transferred remains intact and arrives in the same order in which it was sent. There is no guarantee that the messages or packets sent would reach at all.
Header Size TCP header size is 20 bytes UDP Header size is 8 bytes.
Common Header Fields Source port, Destination port, Check Sum Source port, Destination port, Check Sum
Streaming of data Data is read as a byte stream, no distinguishing indications are transmitted to signal message (segment) boundaries. Packets are sent individually and are checked for integrity only if they arrive. Packets have definite boundaries which are honored upon receipt, meaning a read operation at the receiver socket will yield an entire message as it was originally sent.
Weight TCP is heavy-weight. TCP requires three packets to set up a socket connection, before any user data can be sent. TCP handles reliability and congestion control. UDP is lightweight. There is no ordering of messages, no tracking connections, etc. It is a small transport layer designed on top of IP.
Data Flow Control TCP does Flow Control. TCP requires three packets to set up a socket connection, before any user data can be sent. TCP handles reliability and congestion control. UDP does not have an option for flow control
Acknowledgement Acknowledgement segments No Acknowledgment
Handshake SYN, SYN-ACK, ACK No handshake (connectionless protocol)

以上是关于TCP vs UDP的主要内容,如果未能解决你的问题,请参考以下文章

Netty理论四:TCP vs UDP

TCP与UDP 的区别

TCP和UDP的区别及应用场景

计算机网络,TCP与UDP的区别

TCP/IP详解系列 --- 概念总结01

Linux网络(C++)——网络套接字(TCP/UDP编程模型)多进程,多线程,线程池服务器开发(画图解析)