0
我從建造的server(服務器)例如:升壓C++線程
http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio/examples.html
我做的唯一的事情 - 修改了request_handler.cpp
爲:
// Decode url to path.
std::string request_path;
if (!url_decode(req.uri, request_path))
{
rep = reply::stock_reply(reply::bad_request);
return;
}
// Request path must be absolute and not contain "..".
if (request_path.empty() || request_path[0] != '/'
|| request_path.find("..") != std::string::npos)
{
rep = reply::stock_reply(reply::bad_request);
return;
}
// Fill out the reply to be sent to the client.
rep.status = reply::ok;
std::string filename = "/tmp/test.mp4";
std::ifstream file (filename.c_str(), std::ios::in|std::ios::binary);
char buf[1024000]; // 1MB Buffer read
while (file.read(buf, sizeof(buf)).gcount() > 0)
rep.content.append(buf, file.gcount());
rep.headers.resize(9);
rep.headers[0].name = "Content-Length";
rep.headers[0].value = boost::lexical_cast<std::string>(rep.content.size());
rep.headers[1].name = "Content-Type";
rep.headers[1].value = "video/mp4";
當我打開瀏覽器和點擊服務器,我可以得到視頻,沒有問題。當同樣的情況下,我打開另一個選項卡並打到服務器,沒有任何事情發生。看起來像是等到第一個標籤頁完成。
的目標是有一個處理倍數連接和發送多個文件服務器..