简体   繁体   中英

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. Because TCP has its own flow control, I choose UDP.

Here comes the question: How to achieve this? Can I just send one packet with 600KB size per minute? And how to control the time interval between two packets? Can I just set a time interval with 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.

How to solve this? Or is there a better way?

PS:C language

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. Thereby, pacing at the best rate available. Of course, then there need to be timeouts and re-sends, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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