1
using (Stream stream = _client.GetDownloadStream(filePath))
                    {
                        long toRead = length;

                        stream.Seek(startIndex, SeekOrigin.Begin);

                        using (Stream outStream = context.Response.OutputStream)
                        {
                            // The reported bytes are off, we have to manually keep count
                            // of read bytes
                            while (toRead > 0 && stream.Read(buffer, 0, chunk) > 0)
                            {
                                long readSize = toRead < chunk ? toRead : chunk;
                                outStream.Write(buffer, 0, (int)readSize);
                                outStream.Flush();

                                toRead -= chunk;
                            }
                        }
                    }
                    context.Response.End();
                }
                else
                {
                    ErrorProcessing(context);
                }

            }
            catch (ThreadAbortException ex)
            {
                Utils.Log.Info("Aborted thread - User aborted download", ex);
            }
            >>>>>>>catch (Exception inex)
            {
                if (context.Response.IsClientConnected)
                {
                    Utils.Log.CustomError("Failed to stream recording " +
                                    inex.Message + " " + inex.StackTrace);
                }
            }

What I'm actually trying to do
- Open SFTP connection to my server file storage.
- Begin a Stream.
- Read Bits and try writing to stream back.

What is my Problem?
- The above code perfectly streams audio in Google Chrome, Microsoft Edge and Internet Explorer but fails to do this in Mozilla Firefox.

My Investigation
- Firefox somehow cleans up the session variables and maybe that's why the connection is close, but I might as well discard this because it allows me to download the same file, but does not stream.
- I've also read: The remote host closed the connection. The error code is 0x800704CD but could not find a solution or at least how to avoid the error.

Background
- Developing a C# - .NET application, and need to stream audio from our storage. - I've marked the error by >>>>> in the code. That's where I catch the exception.

Really looking forward to guidance on how to go around this problem.

Community
  • 1
  • 1
Viv
  • 1,706
  • 1
  • 18
  • 27
  • 1
    This is probably not the cause of your issue, but note that your call to stream.Read(buffer, 0, chunk) might return a different number of bytes than you expect. It's not safe to assume that this method will always read the entire chunk, and if it doesn't then you'll end up writing garbage bytes from your buffer into the output stream. – RogerN Nov 07 '16 at 18:58
  • Thank you, I'll keep that in mind. Also, any idea where I should be looking in order to see from the error originates? @RogerN – Viv Nov 07 '16 at 19:01
  • 1
    You might try installing Firebug, if you haven't already, to see if it captures additional information on the client side that might be relevant. Unfortunately the server-side exception that's being generated just doesn't give you much to go on. – RogerN Nov 07 '16 at 19:04
  • Yup, already exhausted that option. @RogerN, thank you anyway. – Viv Nov 07 '16 at 19:19

0 Answers0