0

I have the following function block that complete fine when the client is accessing the server somewhere close like within the US. However, when the client is farther away, like Eastern Europe, the download of large files fails. Any ideas on how I can simulate traffic from a distant IP address? Or any other ideas to make this download and occur faster.

The files are moderatley large, i.e. 100 MB. They are on the same server as the web site is served from. I'm using C# .NET Framework 4.5 IIS 8

System.IO.Stream stream = null;
int bytesToRead = 262144;
byte[] buffer = new Byte[bytesToRead];

try
{
    var response = HttpContext.Current.Response;
    response.ClearContent();
    response.Clear();

    //get file from file system
    string path = Properties.Settings.Default.DownloadDirectory + fileId;
    var fileInfo = new FileInfo(path);
    if (fileInfo.Exists)
    {
        using (stream = new FileStream(path, FileMode.Open))
        {
            response.ContentType = mimeType;

            response.AddHeader("Content-Disposition", "attachment; filename=\"" + name + "\"");
            response.AddHeader("Content-Length", fileInfo.Length.ToString());

            int length;
            do
            {
                if (response.IsClientConnected)
                {
                    length = stream.Read(buffer, 0, bytesToRead);
                    response.OutputStream.Write(buffer, 0, length);
                    response.Flush();
                    buffer = new Byte[bytesToRead];
                }
                else
                {
                    length = -1;
                }
            } while (length > 0);

            stream.Close();
            response.End();
        }
    }
}
4

2 回答 2

0

我们最终使用了 HttpResponse.TransmitFile。它直接写入响应输出流,而不缓冲到内存中。然后我们使用世界各地不同国家的代理对其进行了测试。

于 2013-11-15T14:58:20.550 回答
-1

为了设置测试环境,有一些工具可以模拟 WAN 连接。

如何模拟低带宽、高延迟的环境?

于 2013-11-12T19:23:32.950 回答