通过 UDP 从服务器向 iPhone 发送大量实时处理的数据

发布于 2024-08-23 18:47:24 字数 538 浏览 0 评论 0原文

我正在实施一个远程应用程序。服务器将处理&将数据实时渲染为动画。 (准确地说,是一系列图像)每次渲染图像时,都会通过 UDP 将图像传输到接收 iPhone 客户端。

我研究了一些 UDP,我知道以下几点:

  • UDP 的最大大小约为 65k。

  • 但是,iPhone似乎只能接收41k UDP数据包。 iPhone 似乎无法接收大于此的数据包。

  • 发送多个数据包时,许多数据包被丢弃。这是由于 UDP 处理规模过大造成的。

  • 减少数据包大小会增加不被丢弃的数据包数量,但这意味着需要发送更多数据包。

    减少数据包

我以前从未编写过真正实用的 UDP 应用程序,因此我需要一些关于高效 UDP 通信的指导。在本例中,我们讨论的是从服务器实时传输渲染图像以在 iPhone 上显示。

压缩数据似乎是强制性的,但在这个问题中,我想重点关注 UDP 部分。通常,当我们实现UDP应用时,如果需要实时不间断地发送大量数据,那么如何才能实现高效UDP编程的最佳实践呢?

I'm implementing a remote application. The server will process & render data in real time as animation. (a series of images, to be precise) Each time, an image is rendered, it will be transferred to the receiving iPhone client via UDP.

I have studied some UDP and I am aware of the following:

  • UDP has max size of about 65k.

  • However, it seems that iPhone can only receive 41k UDP packet. iPhone seems to not be able to receive packet larger than that.

  • When sending multiple packets, many packets are being dropped. This is due to oversizing UDP processing.

  • Reducing packet size increase the amount of packets not being dropped, but this means more packets are required to be sent.

I never write real practical UDP applications before, so I need some guidance for efficient UDP communication. In this case, we are talking about transferring rendered images in real time from the server to be displayed on iPhone.

Compressing data seems mandatory, but in this question, I would like to focus on the UDP part. Normally, when we implement UDP applications, what can we do in terms of best practice for efficient UDP programming if we need to send a lot of data non-stop in real time?

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

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

发布评论

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

评论(2

诺曦 2024-08-30 18:47:24

假设您有一个非常具体且充分的理由使用 UDP,并且您需要所有数据到达(即您不能容忍任何数据丢失),那么您需要执行以下操作(假设是单播应用程序):

  1. 在每个数据包的标头中添加一个序列号
  2. 确认每个数据包
  3. 设置一个重传计时器,如果没有收到确认,则重新发送数据包
  4. 跟踪延迟 RTT(往返时间),以便您知道如何进行 很重要,请设置
  5. 可能处理无序数据到达的
  6. 如果这对您的应用增加客户端套接字上的接收缓冲区大小

计时器。此外,您的发送速度可能太快,以至于您在发送计算机上内部丢弃数据包,甚至没有将它们从 NIC 传输到线路上。在某些系统上,在发送套接字上调用 select for write-ablity 可以帮助解决此问题。此外,在 UDP 套接字上调用 connect 可以提高性能,从而减少丢包。

基本上,如果您需要保证数据按顺序传送,那么您将在 UDP 之上重新实现 TCP。如果您使用 UDP 的唯一原因是延迟,那么您可以使用 TCP 并禁用 Nagle 算法< /a>.如果您希望以可靠的低延迟传输打包数据,另一种可能是 SCTP,同样禁用 Nagle。它还可以提供无序交付以进一步加快速度。

我会推荐 Steven 的“Unix Network Planning”,其中有一节介绍高级 UDP 以及何时适合使用 UDP TCP 的。作为说明,他建议不要使用 UDP 进行批量数据传输,尽管现实情况是,如今对于流媒体多媒体应用程序来说,这种情况变得越来越普遍。

Assuming that you have a very specific and good reason for using UDP and that you need all your data to arrive ( i.e. you can't tolerate any lost data ) then there are a few things you need to do ( this assumes a uni-cast application ):

  1. Add a sequence number to the header for each packet
  2. Ack each packet
  3. Set up a retransmit timer which resends the packet if no ack recv'ed
  4. Track latency RTT ( round trip time ) so you know how long to set your timers for
  5. Potentially deal with out of order data arrival if that's important to your app
  6. Increase receive buffer size on client socket.

Also, you could be sending so fast that you are dropping packets internally on the sending machine without them even getting out the NIC onto the wire. On certain systems calling select for write-ablity on the sending socket can help with this. Also, calling connect on the UDP socket can speed up performance leading to less dropped packets.

Basically, if you need guaranteed in-order delivery of your data than you are going to re-implement TCP on top of UDP. If the only reason you use UDP is latency, then you can probably use TCP and disable the Nagle Algorithm. If you want packetized data with reliable low latency delivery another possibility is SCTP, also with Nagle disabled. It can also provide out-of-order delivery to speed things up even more.

I would recommend Steven's "Unix Network Programming" which has a section on advanced UDP and when it's appropriate to use UDP instead of TCP. As a note, he recommends against using UDP for bulk data transfer, although the reality is that this is becoming much more common these days for streaming multimedia apps.

你爱我像她 2024-08-30 18:47:24

小数据包可能比大数据包更好:-)

Small packets is probably better than large packets :-)

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