Beast Logo

PrevUpHomeNext

Messages

After the WebSocket handshake is accomplished, callers may send and receive messages using the message oriented interface. This interface requires that all of the buffers representing the message are known ahead of time:

void echo(beast::websocket::stream<boost::asio::ip::tcp::socket>& ws)
{
    beast::streambuf sb;
    beast::websocket::opcode::value op;
    ws.read(op, sb);

    ws.set_option(beast::websocket::message_type{op});
    ws.write(sb.data());
    sb.consume(sb.size());
}
[Important] Important

Calls to set_option must be made from the same implicit or explicit strand as that used to perform other operations.


PrevUpHomeNext