I copy the websocket example from boost :: beast and run it in a Websocket session, but I don’t know how to convert the resulting multi_buffer to a string.
the code below is the websocket session handler.
void
do_session(tcp::socket &socket) {
try {
websocket::stream <tcp::socket> ws{std::move(socket)};
ws.accept();
while (true) {
boost::beast::multi_buffer buffer;
boost::beast::error_code ec;
ws.read(buffer, ec);
if (ec == websocket::error::closed) {
break;
}
ws.text(ws.got_text());
ws.write(buffer);
}
cout << "Close" << endl;
}
catch (boost::system::system_error const &se) {
if (se.code() != websocket::error::closed)
std::cerr << "Error: " << se.code().message() << std::endl;
}
catch (std::exception const &e) {
std::cerr << "Error: " << e.what() << std::endl;
}
}
Is there a way to convert a buffer to a string?
source
share