Beast Logo


Start an asynchronous operation to write a message to the stream.

    class ConstBufferSequence,
    class WriteHandler>
    ConstBufferSequence const& buffers,
    WriteHandler&& handler);

This function is used to asynchronously write a message to the stream. The function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:

This operation is implemented in terms of one or more calls to the next layer's async_write_some functions, and is known as a composed operation. The program must ensure that the stream performs no other write operations (such as websocket::stream::async_write, websocket::stream::async_write_frame, or websocket::stream::async_close).

The current setting of the websocket::stream::binary option controls whether the message opcode is set to text or binary. If the websocket::stream::auto_fragment option is set, the message will be split into one or more frames as necessary. The actual payload contents sent may be transformed as per the WebSocket protocol settings.





The buffers containing the entire message payload. The implementation will make copies of this object as needed, but ownership of the underlying memory is not transferred. The caller is responsible for ensuring that the memory locations pointed to by buffers remains valid until the completion handler is called.


The handler to be called when the write operation completes. Copies will be made of the handler as required. The function signature of the handler must be:

void handler(
    error_code const& ec     // Result of operation

Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using boost::asio::io_service::post.