我应该知道UDP编程? [英] What should i know about UDP programming?

查看:138
本文介绍了我应该知道UDP编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是说如何连接到插座。关于UDP编程应该知道什么?

I don't mean how to connect to a socket. What should I know about UDP programming?


  • 我需要担心套接字中的坏数据吗?

  • 我应该假设如果我发送200bytes,我可以分别获得120和60字节?

  • 我应该担心另一个连接在同一个端口上发送错误的数据吗?

  • 如果数据未到达,通常我(通常)看不到数据(250ms?1秒?1.75秒?)

  • Do I need to worry about bad data in my socket?
  • I should assume if I send 200bytes I may get 120 and 60 bytes separately?
  • Should I worry about another connection sending me bad data on the same port?
  • If data doesnt arrive typically how long may I (typically) not see data for (250ms? 1 second? 1.75sec?)

我真正需要知道的是什么?

What do I really need to know?

推荐答案


我应该假设如果我发送200bytes i
可以分别获得120和60bytes

"i should assume if i send 200bytes i may get 120 and 60bytes separately?"

数据报您的读取大小将等于您的写入大小。这是因为UDP是数据报协议,而非TCP 协议。但是,在数据包可能被路由器分段或丢弃之前,您只能写入高达MTU大小的数据。对于一般的互联网使用,安全MTU是576字节包括头。

When you're sending UDP datagrams your read size will equal your write size. This is because UDP is a datagram protocol, vs TCP's stream protocol. However, you can only write data up to the size of the MTU before the packet could be fragmented or dropped by a router. For general internet use, the safe MTU is 576 bytes including headers.


我应该担心另一个
连接发送
相同端口上的数据?

"i should worry about another connection sending me bad data on the same port?"

您没有连接,您将收到发送到该端口的任何数据,而不管它来自哪里。

You don't have a connection, you have a port. You will receive any data sent to that port, regardless of where it's from. It's up to you to determine if it's from the right address.


如果数据没有到达通常如何
long可能)没有看到数据
(250ms?1秒?1.75秒?)

If data doesnt arrive typically how long may i (typically) not see data for (250ms? 1 second? 1.75sec?)

数据可能会永久丢失,被延迟,并且数据可以不按顺序到达。 如果任何这些事情困扰你,使用TCP。在UDP之上编写一个可靠的协议是一个非常不重​​要的任务,没有理由这样做几乎所有的应用程序。

Data can be lost forever, data can be delayed, and data can arrive out of order. If any of those things bother you, use TCP. Writing a reliable protocol on top of UDP is a very non trivial task and there is no reason to do so for almost all applications.

这篇关于我应该知道UDP编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆