PDA

View Full Version : با متد زیر آیا از پهنای باند سایت استفاده می شود یا خیر؟



m.alinejad
جمعه 03 آبان 1392, 15:06 عصر
یک فایل mp3 در سایت 1 قرار دارد، با متد زیر این فایل را در سایت 2 خوانده و به کاربر نمایش می دهم، بگونه ای که لینک اصلی برای کاربر سایت 2 مشخص نشود. برای اینکار از این متد استفاده نموده ام :


//Create a stream for the file
Stream stream = null;

//This controls how many bytes to read at a time and send to the client
int bytesToRead = 10000;

// Buffer to read bytes in chunk size specified above
byte[] buffer = new Byte[bytesToRead];

// The number of bytes read
try
{
//Create a WebRequest to get the file
HttpWebRequest fileReq = (HttpWebRequest)HttpWebRequest.Create("http://www.alsacreations.fr/mp3/everywhere.mp3");

//Create a response for this request
HttpWebResponse fileResp = (HttpWebResponse)fileReq.GetResponse();

if (fileReq.ContentLength > 0)
fileResp.ContentLength = fileReq.ContentLength;

//Get the Stream returned from the response
stream = fileResp.GetResponseStream();

// prepare the response to the client. resp is the client Response
var resp = HttpContext.Current.Response;

//Indicate the type of data being sent
resp.ContentType = "application/octet-stream";

//Name the file
string fileName = "everywhere.mp3";
resp.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName);
resp.AddHeader("Content-Length", fileResp.ContentLength.ToString());

int length;
do
{
// Verify that the client is connected.
if (resp.IsClientConnected)
{
// Read data into the buffer.
length = stream.Read(buffer, 0, bytesToRead);

// and write it out to the response's output stream
resp.OutputStream.Write(buffer, 0, length);

// Flush the data
resp.Flush();

//Clear the buffer
buffer = new Byte[bytesToRead];
}
else
{
// cancel the download if client has disconnected
length = -1;
}
} while (length > 0); //Repeat until no data is read
}
finally
{
if (stream != null)
{
//Close the input stream
stream.Close();
}
}

این متد بدرستی کار می کند، تنها سئوالی که هست اینکه با این روش علاوه بر اینکه از پهنای باند (BandWith) سایت 1 استفاده می شود، آیا از پهنای باند سایت 2 نیز استفاده می شود یا خیر؟
(سایت 1 پهنای باند نامحدود و سایت 2 پهنای باند ماهانه محدود دارد)

plus
جمعه 03 آبان 1392, 16:19 عصر
Send در سایت 1 و Send و Receive در سایت 2 استفاده میشه.یعنی برای مثال اگه فایل 10 مگابایت باشه، هر دانلود، 10 مگ از ترافیک سایت 1 و 20 مگ از ترافیک سایت 2 استفاده میکنه...