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

Oct 5 2011 9:47 AM
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
Host: 1.2.3.4
Range: bytes=0-1
Connection: close
User-Agent: AppleCoreMedia/1.0.0.7B367 (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 ([url]http://1.2.3.4/media/sample.mp4[/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

Answers (1)