CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Mar 2005
    .NET 3.5

    [C# / C / C++] Paid project - Send a video file through HTTP

    I need a server-side program which accept requests for video files via HTTP from client applications like quicktime or windows media player, and sends back the files.
    The media player should correctly receive and play the video.

    The requests are like this one:
    GET /media/sample.mp4 HTTP/1.1
    Range: bytes=0-1
    Connection: close
    User-Agent: AppleCoreMedia/ (iPad; U; CPU OS 3_2 like Mac OS X)
    Accept: */*
    Accept-Encoding: identity
    Cookie: __utma=39151136.710240331.1317546773.1317678455.1317758475.7; __utmb=39151136.0.10.1317758475; __utmc=39151136; __utmz=39151136.1317546773.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
    I tried sending it back the video with a code similar to the following (in C#), but after a while the Send or SendFile calls raise an exception: "connection has been forcibly closed by the remote host", before the file has been completely sent.

                     FileInfo fi = new FileInfo(filePath);
                     String headers = "HTTP/1.0 200 OK\r\n";
                     headers += "Content-Type: video/mp4\r\n";
                     headers += "Content-Length: " + fi.Length + "\r\n\r\n";
    client_socket.SendFile(filePath, Encoding.ASCII.GetBytes(headers), null, TransmitFileOptions.UseDefaultWorkerThread );

    Strangely enough, if i try to navigate to the video URL ( with a browser, it downloads it completely without errors, but if i play that url from a media player it fails after some data has been received.
    If i play the file from local, it works, so i don't think it's a media encoding issue.

    If you are able to solve this problem, i'll pay you for a solution to it, of course.

    Thanks in advance
    Last edited by GordonFreeman; October 5th, 2011 at 04:12 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.