I'm trying to make a streaming application using boost with iostream, but the server is not separating the image frame in the receive loop, is getting everything in one file(does not close the file, and continues to receive the other frames in the same file). The only solution i could find was sent a frame for connection, but is leaving the streaming very slow.
currently sending 1 file per connection and everything works (slowly on remote networks)
i want to change it to send multiple files per connection (I think i will have a gain in performance), but I'm having the problem mentioned above.
the "/tmp/img.frame" must be overwritten
below the code I'm using (changed just to make one connection)
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;
}
}