Click here to Skip to main content
15,886,556 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

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.
 
Share this answer
 
Comments
pasztorpisti 19-Aug-13 5:35am    
+5 client side throttling is indeed possible and easy to implement. However in many cases you may want to put this into the server to prevent protocol abuse for example by hacked clients. I don't know asio but on the server side depending on the threading model of the server it can easily happen that you can not implement throttling on top of the network engine as an additional layer. You could do that only by blocking the "data received" handler/callback or whatever of the engine and if the threading model is not 1 thread/client then you end up blocking the whole engine... In some cases this feature must be supported by the engine.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900