我正在尝试使用boost iostream sockets发送和接收文件。读取文件内容并发送到流的最有效方法是什么?在服务器端如何读取此内容并写入文件?
发送:
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
}
}