1
我試圖做一個流媒體應用程序使用提升iostream,但服務器不分離圖像幀 在接收循環,獲取所有內容在一個文件中(不關閉該文件並繼續接收同一文件中的其他幀)。 我能找到的唯一解決方案就是發送了一個連接幀,但是離開流很慢。每個連接發送多個文件與提升iostream
目前每發送連接1個文件,一切工作(慢慢遠程網絡)
我想改變它每個連接(我想我會在性能增益)發送多個文件,但我有上面提到的問題。
的「/tmp/img.frame」必須覆蓋
我使用下面的代碼(改變只是爲了讓一個連接)
void send_()
{
boost::scoped_ptr<screenshot> ptr_screen(new screenshot);
handle_connection = true;
boost::asio::io_service svc;
boost::asio::ip::tcp::iostream stream_(boost::asio::ip::tcp::resolver::query{ "127.0.0.1", "6293" });
boost::iostreams::filtering_ostream out;
out.push(boost::iostreams::zlib_compressor());
out.push(stream_);
while (handle_connection) {
ptr_screen->Start(); // get screen.jpg
std::ifstream ifs("screen.jpg", std::ios::binary);
out << ifs.rdbuf();
out.flush();
ifs.close();
}
}
void receiver_()
{
connection_handle = true;
try
{
boost::asio::io_service io_service;
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), 6293);
boost::asio::ip::tcp::acceptor acceptor(io_service, endpoint);
boost::asio::ip::tcp::iostream stream;
boost::system::error_code ec;
acceptor.accept(*stream.rdbuf(), ec);
if(!stream) { return; }
boost::iostreams::filtering_istream in;
in.push(boost::iostreams::zlib_decompressor());
in.push(stream);
while(connection_handle)
{
std::ofstream ofs("/tmp/img.frame", std::ios::binary); // must be overwritten
copy(in, ofs);
ofs.close();
}
}
catch (std::exception& e)
{
std::cerr << "\n[-] " << e.what() << std::endl;
}
}