UDP 和 TCP 数据包有什么区别?你用它们做什么?

发布于 2024-10-15 08:08:12 字数 111 浏览 2 评论 0原文

我昨天正在配置IPtable。我的同事刚刚问了我这个问题,我无法回答。我意识到我是一个比系统管理员更好的开发人员,并且需要改进。

那么它们是什么?它们是做什么用的?缺点/优点(如果相关的话)。

I was configuring IPtable yesterday. My colleague just asked me this question, and I couldn't anwser. I realized that I'm a much better developper than sysadmin and need to improve that.

So what are they? What are they for? Cons/Pros (if it's relevant).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

掩于岁月 2024-10-22 08:08:13

这些就像基本问题。

UDP :: 用户数据报协议

1)机器之间没有端到端连接(可能在本地网络或互联网中的某个地方)。

2)接收端接收到的数据不是像TCP那样以流的形式,而是作为一个完整的数据块。

3) 在传输层不执行数据包顺序检查。也就是说,如果接收到的数据包出现任何错误,接收方将不会要求将相同的数据包重新发送给发送方。

4) 由于上述行为,发送方端不需要发送缓冲区。

5) 由于没有建立端到端连接。而且不需要握手,UDP 比 TCP 快得多,但可靠性较差。因此主要用于游戏和DNS等。

6) 收到数据包后无需发送确认。

TCP :: 传输控制协议

1) 机器之间维持端到端连接(可能在本地网络或互联网中的某个地方)。

2)接收端收到的数据是TCP中的流。因此,当我们为服务器进行网络编程时,我们首先解析标头,然后根据标头中提到的大小,我们从缓冲区获取更多数量的字节。

3) 错误检查和序列号都已完成。因此,如果任何数据包被无序接收(很少)或出现错误,则需要重新发送该数据包。此外,还涉及许多其他协议用于流量控制(端到端流量控制)。

4) 由于要建立连接、握手和确认,TCP 的运行速度基本上比 UDP 慢。(我认为不是很慢)

5)许多协议使用TCP作为底层传输协议。 HTTP、FTP、TELNET 等。

6) 通信过程包括:

Server:: 1) Socket Open

2) Socket Bind

3) Socket Listen

4) Socket Accept

5) Socket Send/Recv

Client :: 1) Socket Open

2) Socket Connect

3) Socket Send/Recv

还有很多其他差​​异......但以上是最常见的差异。

These are like basic questions.

UDP :: User Datagram Protocol

1) No end to end Connection between to machines (may be in local network or somewhere in the internet).

2) The data received at the receiver end is not in stream as in TCP but as a complete block of data.

3) At the transport layer no packet order check is performed. That is in case of any error in the received packet, the receiver will not ask for resending the same packet to the sender.

4) Because of the above behaviour no sending buffers are required at the sender's end.

5) As no end to end connection is estld. and there are no handshakings required, UDP are pretty much faster but less reliable than TCP. Thus mostly used in gaming and DNS etc..

6) No acknowledgement required to be sent after recieiving packets.

TCP :: Transmission control Protocol

1) End to end Connection is maintained between to machines (may be in local network or somewhere in the internet).

2) The data received at the receiver end is a stream in TCP. Thus, when we do network programming for servers we first parse the header first and then depending upon the size mentioned in the header we obtain that much more number of bytes from the buffer.

3) Error checking and sequence number are all done. Thus in case any packet is received out of order (rarely) or is erred than that packet is made to resend. Also, lots of other protocols are involved for flow control (end to end flow control).

4) As connection establishment , handshaking and acknowledgement is to be done TCP are basically slower in operation than UDP.(Not significantly I believe)

5) Lots of protocols uses TCP as underlying transport protocol. HTTP,FTP,TELNET etc..

6) The communication procedure involves:

Server:: 1) Socket Open

2) Socket Bind

3) Socket Listen

4) Socket Accept

5) Socket Send/Recv

Client :: 1) Socket Open

2) Socket Connect

3) Socket Send/Recv

There are lots of other differeces also..but the above being the most common ones.

孤独患者 2024-10-22 08:08:13

TCP 是一种可靠的协议,可确保您的数据包到达目的地,并用于所有数据必须在各方之间准确传输的应用程序。 TCP 要求双方在数据传输开始之前协商连接,并且它是一种弹性协议,因为它会重复重新发送数据包,直到目标接收者收到该数据包。

UDP 是不可靠的,因为它允许某些数据包在传输过程中丢失。 UDP 的一些应用出现在电影流中,您实际上可以承受丢失帧的损失,而不会影响电影质量。 UDP 不需要双方之间的绑定,并且通常被视为 TCP 的轻量级替代方案。

这里有一个很好的表格:TCP vs UDP

TCP is a reliable protocol which ensures that your packets reach their destination and is used in applications where all data must me trasfered accurately between parties. TCP requires both parties to negotiate a connection before data transfer can start and it is a resilient protocol since it will repeatedly resend a packet until that packet is received by the intended recipient.

UDP is unreliable in a sense that it allows some packets to be lost in transit. Some applications of UDP are found in movie streaming where you can actually afford to lose a frame and not jeopardize movie quality. UDP does not need binding between the two parties and is often looked at as a light alternative to TCP.

A nice table is found here:TCP vs UDP

稀香 2024-10-22 08:08:13

PR的回答大部分是正确的,但不完整。

TCP 是一种可靠的、连接的流协议。它的数据视图是主机之间的双向字节流:您发送的任何字节都将以相同的顺序到达另一端,至少就应用程序而言(操作系统将在需要时重新排列数据包)。

UDP 是一种非连接数据报协议。它的数据视图是离散数据报或消息的视图,不能保证这些消息实际到达收件人,或者它们按照发送的顺序到达。它确实保证如果消息到达,它会完整地到达并且不会被修改。

P.R.'s answer is mostly correct, but incomplete.

TCP is a reliable, connected stream protocol. Its view of data is that of a bidirectional stream of bytes between hosts: whatever bytes you send will arrive at the other end in the same order, at least as far as the application is concerned (the OS will rearrange packets if needed).

UDP is an unconnected datagram protocol. Its view of data is that of discrete datagrams, or messages, with no guarantee that these messages actually reach their recipient, or that they arrive in the order they were sent. It does guarantee that if a message arrives, it arrives in its entirety and without modification.

聽兲甴掵 2024-10-22 08:08:13

这个网站可能对 UDP 和 TCP 的实际差异提供了最简单的解释。从实现的角度来看,请参阅这个问题

简而言之:TCP 的工作方式有点像挂号信,而 UDP 则有点像普通信件 - 对于后者,您永远不知道收件人是否收到您发送的数据包。

This website probably offers the simplest explanation to the actual difference of UDP and TCP. From implementation point of view, see this question.

For short answer: TCP works kind of like registered letter when UDP is kind of like ordinary letter - with the latter you never know whether the recipient got the packet you sent.

枕头说它不想醒 2024-10-22 08:08:13

克里斯是对的!
从谷歌中删除的一个奇特链接是:http://www.skullbox.net/tcpudp.php

chris is right!
One fancy link dropping out of google is: http://www.skullbox.net/tcpudp.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文