简体   繁体   English

如何控制UDP套接字的吞吐量?

[英]How to control the throughput of an UDP socket?

What I want to achieve is to output data through a socket in a stable speed, such as 600KB/s. 我要实现的是通过套接字以稳定的速度(例如600KB / s)输出数据。 Because TCP has its own flow control, I choose UDP. 因为TCP有其自己的流控制,所以我选择UDP。

Here comes the question: How to achieve this? 问题来了:如何实现这一目标? Can I just send one packet with 600KB size per minute? 我可以每分钟发送一个大小为600KB的数据包吗? And how to control the time interval between two packets? 以及如何控制两个数据包之间的时间间隔? Can I just set a time interval with select() : 我可以使用select()设置时间间隔吗?

select(fd, NULL, NULL, NULL, &tv); //tv is set as 1 second

I doubt that, because a socket's sendto() is running at the application layer and we cannot ensure that the packet has been sent by the OS kernel. 我对此表示怀疑,因为套接字的sendto()在应用程序层上运行,并且我们无法确保数据包已由OS内核发送。

How to solve this? 如何解决呢? Or is there a better way? 或者,还有更好的方法?

PS:C language PS:C语言

The simplest approach is to just wait between sends long enough to keep the total throughput down. 最简单的方法是在两次发送之间等待足够长的时间,以使总吞吐量降低。 This will keep the 'average' send rate down to the desired value. 这将使“平均”发送速率降低到所需的值。

However, a much better implementation is for the receiver to send an ACK after receiving an input. 但是,更好的实现方式是接收器在接收到输入后发送ACK。 Thereby, pacing at the best rate available. 因此,以可用的最佳速率进行起搏。 Of course, then there need to be timeouts and re-sends, etc. 当然,然后需要超时和重新发送等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM