473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Restricting bandwidth for download stream

Hi all,

I have an asp.net application from which registered users can download
files. What I want to implement is a bandwidth restriction for certain
users. What I DON'T want to do is restrict the bandwidth on the IIS
side. It really should be handled in the code. Here is a code snippet
showing how downloads are currently handled (standard implementation I
guess):

// fs: FileStream
while (offset < size && Response.IsClientConnected)
{
if (size-offset < bufSize)
{
bufSize = size-offset;
buf = new byte[bufSize];
}
fs.Read(buf, 0, (int)bufSize);
Response.OutputStream.Write(buf, 0, (int)bufSize);
if (Response.IsClientConnected)
Response.Flush();
else
break;
offset += bufSize;
}

everything works fine, but I can't find a way to decrease the speed of
the download (except perhaps adding Sleep() or decreasing bufsize which
would both be a *dirty* solution). Anyone has an idea?

Thanks in advance

Hannes

Nov 19 '05 #1
1 1190
first be sure buffering is turned off. loop writing chunks with sleeps as
you guessed.

a bit about about flow. when the download request hits iis, it uses a thread
and pipe to talk to asp.net worker process. asp.net dedicates an io thread
to handle the pipe, and starts a worker thread to process the request.

if you add delays, all these threads will be tied up, and the number of
concurrent downloads will drop. while you can bump up the threads pools, it
is still not a very high number (200 concurrent downloads per server is
about the max).

you may find that limiting bandwidth is not very useful. you might look at
limiting the number of downloads in a given time rather than slowing down a
download.

-- bruce (sqlwork.com)
"hoenes1" <le****@twism4life.de> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi all,

I have an asp.net application from which registered users can download
files. What I want to implement is a bandwidth restriction for certain
users. What I DON'T want to do is restrict the bandwidth on the IIS
side. It really should be handled in the code. Here is a code snippet
showing how downloads are currently handled (standard implementation I
guess):

// fs: FileStream
while (offset < size && Response.IsClientConnected)
{
if (size-offset < bufSize)
{
bufSize = size-offset;
buf = new byte[bufSize];
}
fs.Read(buf, 0, (int)bufSize);
Response.OutputStream.Write(buf, 0, (int)bufSize);
if (Response.IsClientConnected)
Response.Flush();
else
break;
offset += bufSize;
}

everything works fine, but I can't find a way to decrease the speed of
the download (except perhaps adding Sleep() or decreasing bufsize which
would both be a *dirty* solution). Anyone has an idea?

Thanks in advance

Hannes

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dany | last post by:
Wrote a script (tried to;) which should force to download a pdf-file, but it doesn't work on every browser. What should be changed ? SCRIPT: --------- <% Dim Stream Dim Contents
0
by: Martin Raychev | last post by:
Hi everybody, I have a need for a web app that will allow a flash client to download files at a specified speed. I am using Flash for an application of mine which downloads JPG slides to...
5
by: Thomas Andersson | last post by:
Hi, I am trying to find a working solution for download of large files (400-800 MB)... But this seems almost impossible to find a working example. I have tried Response.Transmitfile, this...
2
by: hoenes1 | last post by:
Hi all, I have an asp.net application from which registered users can download files. What I want to implement is a bandwidth restriction for certain users. What I DON'T want to do is restrict...
8
by: Dominic Martin | last post by:
Hi, I need to setup an ODBC link over our Internet connection between MS Access (local) and a MySQL server (Remote - the local PC has the MySQL ODBC driver installed). What kind of bandwidth...
9
by: Chibi | last post by:
I'm writing an application that's bandwidth intense. My available bandwidth is 1.5Mbps (cable modem) and I know I can reach around 1.4Mbps, if not more. The application I am writing right now...
3
by: Raj | last post by:
is it possible using C# dotnet to control the bandwidth usage means the transfer rate of download and upload? Thanks!
4
by: rony_16 | last post by:
Hi, I have a program that connects to a site With WebRequest and WebResponse . The response of this site is a file (csv file). The problem is that the file do not comes as a stream , hi is a part...
16
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will...
7
by: Andrew Poulos | last post by:
Is there a way where I can "guess" what relative speed the user's connection is? Currently, the client is wanting some graphical intensive content and I'd like to be able to warn users on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.