s4服务器udp协议,networking - When is it appropriate to use UDP instead of TCP? - Stack Overflow

TCP has head-of-queue blocking, as it guarantees complete and in-order

delivery, so when a packet gets lost in transit, it has to wait for a

retransmit of the missing packet, whereas UDP delivers packets to the

application as they arrive, including duplicates and without any

guarantee that a packet arrives at all or which order they arrive (it

really is essentially IP with port numbers and an (optional) payload

checksum added), but that is fine for telephony, for example, where it

usually simply doesn't matter when a few milliseconds of audio are

missing, but delay is very annoying, so you don't bother with

retransmits, you just drop any duplicates, sort reordered packets into

the right order for a few hundred milliseconds of jitter buffer, and

if packets don't show up in time or at all, they are simply skipped,

possible interpolated where supported by the codec.

Also, a major part of TCP is flow control, to make sure you get as

much througput as possible, but without overloading the network (which

is kinda redundant, as an overloaded network will drop your packets,

which means you'd have to do retransmits, which hurts throughput), UDP

doesn't have any of that - which makes sense for applications like

telephony, as telephony with a given codec needs a certain amount of

bandwidth, you can not "slow it down", and additional bandwidth also

doesn't make the call go faster.

In addition to realtime/low latency applications, UDP makes sense for

really small transactions, such as DNS lookups, simply because it

doesn't have the TCP connection establishment and teardown overhead,

both in terms of latency and in terms of bandwidth use. If your

request is smaller than a typical MTU and the repsonse probably is,

too, you can be done in one roundtrip, with no need to keep any state

at the server, and flow control als ordering and all that probably

isn't particularly useful for such uses either.

And then, you can use UDP to build your own TCP replacements, of

course, but it's probably not a good idea without some deep

understanding of network dynamics, modern TCP algorithms are pretty

sophisticated.

Also, I guess it should be mentioned that there is more than UDP and

TCP, such as SCTP and DCCP. The only problem currently is that the

(IPv4) internet is full of NAT gateways which make it impossible to

use protocols other than UDP and TCP in end-user applications.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值