什么时候使用UDP代替TCP? [关闭]

本文翻译自:When is it appropriate to use UDP instead of TCP? [closed]

Since TCP guarantees packet delivery and thus can be considered "reliable", whereas UDP doesn't guarantee anything and packets can be lost. 由于TCP保证了数据包的传递,因此可以被认为是“可靠的”,而UDP不保证任何内容,因此数据包可能会丢失。 What would be the advantage of transmitting data using UDP in an application rather than over a TCP stream? 在应用程序中而不是通过TCP流使用UDP传输数据的优势是什么? In what kind of situations would UDP be the better choice, and why? 在哪种情况下,UDP是更好的选择,为什么?

I'm assuming that UDP is faster since it doesn't have the overhead of creating and maintaining a stream, but wouldn't that be irrelevant if some data never reaches its destination? 我假设UDP更快,因为它没有创建和维护流的开销,但是如果某些数据永远不会到达目的地,那不是无关紧要的吗?


#1楼

参考:https://stackoom.com/question/4C4E/什么时候使用UDP代替TCP-关闭


#2楼

We know that the UDP is a connection-less protocol, so it is 我们知道UDP是一种无连接协议,因此

  1. suitable for process that require simple request-response communication. 适用于需要简单的请求-响应通信的过程。
  2. suitable for process which has internal flow ,error control 适用于内部流程,错误控制的过程
  3. suitable for broad casting and multicasting 适用于广泛的广播和组播

Specific examples: 具体示例:

  • used in SNMP 在SNMP中使用
  • used for some route updating protocols such as RIP 用于某些路由更新协议,例如RIP

#3楼

视频流是使用UDP的完美示例。


#4楼

UDP确实具有较少的开销,并且非常适合执行诸如流传输实时数据(如音频或视频)之类的事情,或者在任何情况下如果数据丢失都可以。


#5楼

If a TCP packet is lost, it will be resent. 如果TCP数据包丢失,它将被重新发送。 That is not handy for applications that rely on data being handled in a specific order in real time. 对于依赖于以特定顺序实时处理数据的应用程序而言,这并不方便。

Examples include video streaming and especially VoIP (eg Skype ). 示例包括视频流,尤其是VoIP (例如Skype )。 In those instances, however, a dropped packet is not such a big deal: our senses aren't perfect, so we may not even notice. 但是,在这些情况下,丢包并不是什么大问题:我们的感觉并不完美,因此我们甚至可能不会注意到。 That is why these types of applications use UDP instead of TCP. 这就是为什么这些类型的应用程序使用UDP而不是TCP。


#6楼

The "unreliability" of UDP is a formalism. UDP的“不可靠性”是形式主义。 Transmission isn't absolutely guaranteed. 传输不是绝对保证的。 As a practical matter, they almost always get through. 实际上,它们几乎总是能够通过。 They just aren't acknowledged and retried after a timeout. 超时后,它们不会被确认并重试。

The overhead in negotiating for a TCP socket and handshaking the TCP packets is huge. 协商TCP套接字和握手TCP数据包的开销很大。 Really huge. 真的很大。 There is no appreciable UDP overhead. 没有明显的UDP开销。

Most importantly, you can easily supplement UDP with some reliable delivery hand-shaking that's less overhead than TCP. 最重要的是,您可以通过一些可靠的交付握手协议轻松补充UDP,而这些握手协议的开销要比TCP少。 Read this: http://en.wikipedia.org/wiki/Reliable_User_Datagram_Protocol 阅读此内容: http : //en.wikipedia.org/wiki/Reliable_User_Datagram_Protocol

UDP is useful for broadcasting information in a publish-subscribe kind of application. UDP对于在发布-订阅类型的应用程序中广播信息很有用。 IIRC, TIBCO makes heavy use of UDP for notification of state change. IIRC,TIBCO大量使用UDP来通知状态更改。

Any other kind of one-way "significant event" or "logging" activity can be handled nicely with UDP packets. UDP数据包可以很好地处理任何其他类型的单向“重大事件”或“日志记录”活动。 You want to send notification without constructing an entire socket. 您要发送通知而无需构造整个套接字。 You don't expect any response from the various listeners. 您不会期望各种听众有任何回应。

System "heartbeat" or "I'm alive" messages are a good choice, also. 系统“心跳”或“我还活着”消息也是一个不错的选择。 Missing one isn't a crisis. 错过一个不是危机。 Missing half a dozen (in a row) is. (连续)丢失六打。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值