5

I want to limit the bandwidth of all downloads and uploads to be performed in the application.

The reason is that the application runs code not written by me. I don't want some malicious code to over use the network resource.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Erik Sapir
  • 23,209
  • 28
  • 81
  • 141

1 Answers1

6

Here is a link on SO that covers a similar question:
How can I rate limit an upload using TcpClient?

In a nutshell, you need to detect the bandwidth of the connected socket and then sleep overly fast connections.

Here is a link to a CodeProject source that makes use of throttling techniques:
http://www.codeproject.com/KB/IP/Bandwidth_throttling.aspx

Community
  • 1
  • 1
Joel Etherton
  • 37,325
  • 10
  • 89
  • 104
  • I don't have control over the Stream. As i said, the download/upload is done from code that is not written by me. I just execute a dll function – Erik Sapir Sep 13 '11 at 12:05
  • @Erik Sapir: What do you have control over? Even the stream needs to receive data. It's not inconceivable that you could pass the data to the stream in throttled increments. – Joel Etherton Sep 13 '11 at 12:17
  • I don't have any control over the code that perform network operations. I just call a function in a dll. – Erik Sapir Sep 13 '11 at 12:21
  • @Erik Sapir: What does the function look like? Is it taking a streamreader, a string, xml? – Joel Etherton Sep 13 '11 at 12:25
  • I don't know how it would look like. The function in the dll are not mine - other programmers can load their own dll files and call them from my application. Their code can also perform network operations, which i want to limit – Erik Sapir Sep 13 '11 at 12:28
  • @Erik Sapir: If you want to control anything, you need to have this access. You can't limit what you don't control. If you want to limit any kind of network operations, you need to program a network operations layer that has limitation functionality and then mandate that all consuming dlls make use of that API. – Joel Etherton Sep 13 '11 at 12:31
  • That is not correct. Programs like net limiter can limit download and upload speed of a process. I want to do the same – Erik Sapir Sep 13 '11 at 12:41
  • @Erik Sapir: Net Limiter intercepts the network traffic at the network layer. It occurs outside any applications which run in the application layer. Your question asks how to do it from within your application. You would need to run your own external program similar to Net Limiter in order to accomplish this. – Joel Etherton Sep 13 '11 at 12:52
  • It does not have to be from within my application. If i can limit from other process, it is also OK – Erik Sapir Sep 13 '11 at 13:02