...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Provides message-oriented functionality using WebSocket.
Defined in header <boost/beast/websocket/stream.hpp>
template< class NextLayer, bool deflateSupported> class stream
Name |
Description |
---|---|
The type of the executor associated with the object. |
|
Indicates if the permessage-deflate extension is supported. |
|
The type of the lowest layer. |
|
The type of the next layer. |
Name |
Description |
---|---|
Read and respond to a WebSocket HTTP Upgrade request. Respond to a WebSocket HTTP Upgrade request. |
|
Read and respond to a WebSocket HTTP Upgrade request. |
|
Start reading and responding to a WebSocket HTTP Upgrade request. Start responding to a WebSocket HTTP Upgrade request. |
|
Start reading and responding to a WebSocket HTTP Upgrade request. |
|
Start an asynchronous operation to send a WebSocket close frame. |
|
Start an asynchronous operation to send an upgrade request and receive the response. |
|
Start an asynchronous operation to send an upgrade request and receive the response. |
|
Start an asynchronous operation to send a WebSocket ping frame. |
|
Start an asynchronous operation to send a WebSocket pong frame. |
|
Read a message asynchronously. |
|
Read part of a message asynchronously. |
|
Start an asynchronous operation to write a message to the stream. |
|
Start an asynchronous operation to send a message frame on the stream. |
|
Set the automatic fragmentation option. Returns true if the automatic fragmentation option is set. |
|
Set the binary message write option. Returns true if the binary message write option is set. |
|
Send a WebSocket close frame. |
|
Set a callback to be invoked on each incoming control frame. Reset the control frame callback. |
|
Get the executor associated with the object. |
|
Get the permessage-deflate extension options. |
|
Returns true if the latest message data indicates binary. |
|
Returns true if the latest message data indicates text. |
|
Send an HTTP WebSocket Upgrade request and receive the response. |
|
Send an HTTP WebSocket Upgrade request and receive the response. |
|
Returns true if the last completed read finished the current message. |
|
Returns true if the stream is open. |
|
Get a reference to the lowest layer. |
|
Get a reference to the next layer. |
|
Assignment. |
|
Send a WebSocket ping frame. |
|
Send a WebSocket pong frame. |
|
Read a message. |
|
Set the maximum incoming message size option. Returns the maximum incoming message size setting. |
|
Returns a suggested maximum buffer size for the next call to read. |
|
Read part of a message. |
|
Returns the close reason received from the peer. |
|
Set whether the PRNG is cryptographically secure. |
|
Set the permessage-deflate extension options. |
|
Constructor. |
|
Set the text message write option. Returns true if the text message write option is set. |
|
Write a message to the stream. |
|
Set the write buffer size option. Returns the size of the write buffer. |
|
Write partial message data on the stream. |
|
Destructor. |
The websocket::stream
class template provides asynchronous
and blocking message-oriented functionality necessary for clients and servers
to utilize the WebSocket protocol.
For asynchronous operations, the application must ensure that they are are all performed within the same implicit or explicit strand.
Distinct objects: Safe.
Shared objects: Unsafe. The application must also ensure that all asynchronous operations are performed within the same implicit or explicit strand.
To use the websocket::stream
template with an ip::tcp::socket
,
you would write:
websocket::stream<ip::tcp::socket> ws{io_context};
Alternatively, you can write:
ip::tcp::socket sock{io_context}; websocket::stream<ip::tcp::socket&> ws{sock};
Type |
Description |
---|---|
|
The type representing the next layer, to which data will be read and written during operations. For synchronous operations, the type must support the SyncStream concept. For asynchronous operations, the type must support the AsyncStream concept. |
|
A |
A stream object must not be moved or destroyed while there are pending asynchronous operations associated with it.
AsyncStream, DynamicBuffer, SyncStream
Convenience header <boost/beast/websocket.hpp>