先决条件 – 传输层职责、TCP、UDP
Transmission control protocol (TCP) | User datagram protocol (UDP) |
---|---|
TCP is a connection-oriented protocol. Connection-orientation means that the communicating devices should establish a connection before transmitting data and should close the connection after transmitting the data. | UDP is the Datagram oriented protocol. This is because there is no overhead for opening a connection, maintaining a connection, and terminating a connection. UDP is efficient for broadcast and multicast type of network transmission. |
TCP is reliable as it guarantees the delivery of data to the destination router. | The delivery of data to the destination cannot be guaranteed in UDP. |
TCP provides extensive error checking mechanisms. It is because it provides flow control and acknowledgement of data. | UDP has only the basic error checking mechanism using checksums. |
Sequencing of data is a feature of Transmission Control Protocol (TCP). this means that packets arrive in-order at the receiver. | There is no sequencing of data in UDP. If the order is required, it has to be managed by the application layer. |
TCP is comparatively slower than UDP. | UDP is faster, simpler, and more efficient than TCP. |
Retransmission of lost packets is possible in TCP, but not in UDP. | There is no retransmission of lost packets in the User Datagram Protocol (UDP). |
TCP has a (20-60) bytes variable length header. | UDP has an 8 bytes fixed-length header. |
TCP is heavy-weight. | UDP is lightweight. |
TCP doesn’t support Broadcasting. | UDP supports Broadcasting. |
TCP is used by HTTP, HTTPs, FTP, SMTP and Telnet. | UDP is used by DNS, DHCP, TFTP, SNMP, RIP, and VoIP. |
一个简短的例子来清楚地理解差异:
假设有两个房子,H1 和 H2,一封信必须从 H1 发送到 H2。但这两个房子之间有一条河。现在我们如何发送这封信?
解决方案1:在河上架一座桥,然后就可以交付了。
解决方案 2:通过鸽子交付。
将第一个解决方案视为 TCP。必须建立连接(桥接)才能传递数据(信件)。
数据是可靠的,因为它会直接到达另一端而不会丢失数据或错误。
第二种解决方案是UDP。发送数据不需要连接。
这个过程比 TCP 快,我们需要建立一个连接(网桥)。但数据并不可靠:我们不知道鸽子是否会朝着正确的方向前进,或者它会在途中掉信,或者在旅行中遇到一些问题。类型