c++ - How to convert boost beast multi_buffer to string? -


i copy websocket example boost::beast website , run websocket session work fine don't know how convert received multi_buffer string.

below code websocket session handler.

void do_session(tcp::socket &socket) {     try {         // construct stream moving in socket         websocket::stream <tcp::socket> ws{std::move(socket)};          // accept websocket handshake         ws.accept();          while (true) {             // buffer hold incoming message             boost::beast::multi_buffer buffer;              // read message             boost::beast::error_code ec;             ws.read(buffer, ec);              if (ec == websocket::error::closed) {                 break;             }              // echo message             ws.text(ws.got_text());             ws.write(buffer);         }          cout << "close" << endl;     }     catch (boost::system::system_error const &se) {         // indicates session closed         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 way convert buffer string ?

you can use buffers on buffer.data()

std::cout << "data read:   " << boost::beast::buffers(buffer.data()) <<  std::endl; 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -