HttpWebRequest.GetResponse:"The remote host closed the connection. The error code is 0x800703E3"

2

I have written a streaming video url app(.NET Framework 4.0) that gets files to a remote server(S3 Signed URL) using generic Handler(.ashx), and then play the handler response in a html5 video tag. Here is the main streaming s3 url code:

<div><video width="500px" height="500px" src="http://localhost:62489/Handler.ashx" autoplay="autoplay" controls="controls"></video>

Generic Handler(.ashx)

public void ProcessRequest(HttpContext context)
{
    try
    {
        HttpRequest Request = context.Request;
        //Assign S3 URl
        string OrginalUrl = "https://s3.amazonaws.com/test/1gb.mp4";
        System.Net.HttpWebRequest wreq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(OrginalUrl);
        wreq.Method = System.Net.WebRequestMethods.Http.Get;
        wreq.ReadWriteTimeout = System.Threading.Timeout.Infinite;
        wreq.Timeout = System.Threading.Timeout.Infinite;
        wreq.KeepAlive = false;
        wreq.ProtocolVersion = System.Net.HttpVersion.Version10;
        using (System.Net.HttpWebResponse wresp = (System.Net.HttpWebResponse)wreq.GetResponse())
        {
            using (Stream mystream = wresp.GetResponseStream())
            {
                using (BinaryReader reader = new BinaryReader(mystream))
                {
                    Int64 length = Convert.ToInt32(wresp.ContentLength);
                    context.Response.Clear();
                    context.Response.Buffer = false;
                    context.Response.BufferOutput = false;
                    context.Response.AddHeader("Content-Type", "application/octet-stream");
                    context.Response.AddHeader("Content-Length", length.ToString());
                    byte[] buffer = new byte[4096];
                    while (true)
                    {
                        int bytesRead = mystream.Read(buffer, 0, buffer.Length);
                        if (bytesRead == 0) break;
                        if (context.Response.IsClientConnected)
                        {
                            context.Response.OutputStream.Write(buffer, 0, bytesRead);
                            context.Response.OutputStream.Flush();
                        }
                    }
                }
            }
        }

    }
    catch (Exception e)
    {
    }
}

My application works properly for all small files, but I get the following error when I try to send larger files (1 GB).I looked into my application log file, and was able to given the following info:

Exception :The remote host closed the connection. The error code is 0x800703E3


System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()
System.Web.HttpResponse.Flush(Boolean finalFlush)
System.Web.HttpResponse.Flush()
System.Web.HttpWriter.WriteFromStream(Byte[] data, Int32 offset, Int32 size)
System.Web.HttpResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count)
ProcessRequest(HttpContext context) in d:\test\Handler\S3StreamingVideo.ashx.cs:line 60

The failure occurs 7 minutes after I call request.GetResponse() the remote connection was closed. Please help me,how to fix this issue?

Thanks

asp.net
amazon-s3
httphandler
asked on Stack Overflow Feb 3, 2015 by user1070716

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0