Beast Logo



Ping callback option.

using ping_callback = implementation-defined;

Sets the callback to be invoked whenever a ping or pong is received during a call to one of the following functions:

Unlike completion handlers, the callback will be invoked for each received ping and pong during a call to any synchronous or asynchronous read function. The operation is passive, with no associated error code, and triggered by reads.

The signature of the callback must be:

    bool is_pong,               // `true` if this is a pong
    ping_data const& payload    // Payload of the pong frame

The value of is_pong will be true if a pong control frame is received, and false if a ping control frame is received.

If the read operation receiving a ping or pong frame is an asynchronous operation, the callback will be invoked using the same method as that used to invoke the final handler.


Objects of this type are used with beast::websocket::stream::set_option. To remove the ping callback, construct the option with no parameters: set_option(ping_callback{})


Header: beast/websocket/option.hpp

Convenience header: beast/websocket.hpp