如何在asio上限制tcp套接字的速度? [英] how to limit speed of tcp socket on asio?

查看:108
本文介绍了如何在asio上限制tcp套接字的速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



任何人都可以帮助我!



我想知道是否有一些在asio上限制TCP套接字速度的方法?



如果我的应用程序打开套接字并开始向我的服务器发送文件,请提供示例!如何限制上传速度?



如果我想限制为100kb / s,有什么办法吗?任何人都有任何想法:我怎么能实现这个目标?



谢谢

Hi All,

Anyone can help-me!

I want know if have some way to limit speed of tcp socket on asio?

For sample if my app open a socket and start to send a file to my server! How to limit upload speed?

If I want limit to 100kb/s, have any way? Anyone have any idea: how I can achieves this?

Thanks

推荐答案

你可以确定这个包大小,并实现一个计时器,通过在程序中手动计数并观察计时器,您不会发送超过每秒'x'字节。如果您发送的数据相当大,您可以将数据包大小估计为大致有效负载字节数。



这个答案假设您是自己发送的协议,而不是FTP或http或类似。你需要自己进行限制。
You can determine the packet size, and implement a timer so that you don't send any more than 'x' bytes per second by counting manually in your program and watching the timer. If the data you are sending is reasonably large, you can estimate the packet size as roughly the number of payload bytes.

This answer assumes that you are sending by your own protocol, and not FTP or http or similar. You need to do the throttling yourself.


这篇关于如何在asio上限制tcp套接字的速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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