Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

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_some, 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.


Invoked when the operation completes. The handler may be moved or copied as needed. The function signature of the handler must be:

void handler(
    error_code const& ec,           // Result of operation
    std::size_t bytes_transferred   // Number of bytes written from the
                                    // buffers. If an error occurred,
                                    // this will be less than the sum
                                    // of the buffer sizes.

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_context::post.