ブーストiostreamソケットを使用してファイルを送受信しようとしています。ファイルの内容を読み込んでストリームに送信する最も効率的な方法は何ですか?そして、サーバー側でこのコンテンツを読んでファイルに書き込む方法は?ブーストiostreamソケットでファイルを読み書きする
を送る:
boost::asio::io_service svc;
using boost::asio::ip::tcp;
tcp::iostream sockstream(tcp::resolver::query{ "127.0.0.1", "3780" });
std::ifstream fs;
fs.open("img.jpg", std::ios::binary);
sockstream << // send file to stream
は受信:
boost::asio::io_service ios;
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), 3780);
boost::asio::ip::tcp::acceptor acceptor(ios, endpoint);
for (;;)
{
boost::asio::ip::tcp::iostream stream;
boost::system::error_code ec;
acceptor.accept(*stream.rdbuf(), ec);
if (!ec) {
std::ofstream of;
of.open("rcv.jpg", std::ios::binary);
// read the file content with stream
// write content to file
}
}
どのような意味で効率的ですか? –
@DanMašek私は(以前の質問から)大きなファイル(すなわちストリーミング)のためにメモリ要件が大きくならないと仮定しています – sehe