درود عزیزان
کسی میدونه چطوری میتونم سرعت دانلود از اینترنت رو روی کلاینت ها کنترل کنم؟ البته با c#!
کسی میدونه چطوری میتونم سرعت دانلود از اینترنت رو روی کلاینت ها کنترل کنم؟ البته با c#!
امتیاز موضوع:
Title: محدود کردن سرعت دانلود
حالت موضوعی |
Bandwidth throttling in C# windows application
//Apply bandwidth control
int uploadLimit = GlobalClass.GetFileUploadLimit();
if (uploadLimit > 0)
{
long bps = uploadLimit * 1024;
const int BufferSize = 8192;
MemoryStream mstream = new MemoryStream();//Stream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, BufferSize);
// Openup source stream.
using (FileStream sourceStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, BufferSize))
{
// Create throttled destination stream.
ThrottledStream destinationStream = new ThrottledStream(mstream, bps);
byte[] buffer = new byte[BufferSize];
int readCount = sourceStream.Read(buffer, 0, BufferSize);
while (readCount > 0)
{
destinationStream.Write(buffer, 0, readCount);
readCount = sourceStream.Read(buffer, 0, BufferSize);
client.FileUpload(Convert.ToInt16(userId), System.IO.Path.GetFileName(fileName), buffer);//Webservice: Here is the problem
}
}
}
Bandwidth throttling in C# windows application
//Apply bandwidth control
int uploadLimit = GlobalClass.GetFileUploadLimit();
if (uploadLimit > 0)
{
long bps = uploadLimit * 1024;
const int BufferSize = 8192;
MemoryStream mstream = new MemoryStream();//Stream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, BufferSize);
// Openup source stream.
using (FileStream sourceStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, BufferSize))
{
// Create throttled destination stream.
ThrottledStream destinationStream = new ThrottledStream(mstream, bps);
byte[] buffer = new byte[BufferSize];
int readCount = sourceStream.Read(buffer, 0, BufferSize);
while (readCount > 0)
{
destinationStream.Write(buffer, 0, readCount);
readCount = sourceStream.Read(buffer, 0, BufferSize);
client.FileUpload(Convert.ToInt16(userId), System.IO.Path.GetFileName(fileName), buffer);//Webservice: Here is the problem
}
}
}