Files
boost_beast/doc/qbk/06_websocket/1_streams.qbk

67 lines
2.2 KiB
Plaintext
Raw Normal View History

2017-06-03 18:40:28 -07:00
[/
2017-07-28 19:32:33 -07:00
Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
2017-06-03 18:40:28 -07:00
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
2017-07-28 19:32:33 -07:00
Official repository: https://github.com/boostorg/beast
2017-06-03 18:40:28 -07:00
]
2017-06-16 19:27:00 -07:00
[section Creating Streams]
2017-06-03 18:40:28 -07:00
The interface to the WebSocket implementation is a single template class
2017-07-23 22:49:57 -07:00
[link beast.ref.boost__beast__websocket__stream `stream`]
2017-06-03 18:40:28 -07:00
which wraps an existing network transport object or other type of
octet oriented stream. The wrapped object is called the "next layer"
and must meet the requirements of __SyncStream__ if synchronous
operations are performed, __AsyncStream__ if asynchronous operations
are performed, or both. Any arguments supplied during construction of
the stream wrapper are passed to next layer's constructor.
Here we declare a websocket stream over a TCP/IP socket with ownership
of the socket. The `io_service` argument is forwarded to the wrapped
socket's constructor:
2017-06-07 16:30:49 -07:00
[ws_snippet_2]
2017-06-03 18:40:28 -07:00
[heading Using SSL]
To use WebSockets over SSL, use an instance of the `boost::asio::ssl::stream`
class template as the template type for the stream. The required `io_service`
and `ssl::context` arguments are forwarded to the wrapped stream's constructor:
2017-06-07 16:30:49 -07:00
[wss_snippet_1]
[wss_snippet_2]
2017-06-03 18:40:28 -07:00
[important
Code which declares websocket stream objects using Asio SSL types
must include the file [include_file beast/websocket/ssl.hpp].
2017-06-03 18:40:28 -07:00
]
[heading Non-owning References]
If a socket type supports move construction, a websocket stream may be
2017-06-04 17:25:55 -07:00
constructed around the already existing socket by invoking the move
2017-06-03 18:40:28 -07:00
constructor signature:
2017-06-07 16:30:49 -07:00
[ws_snippet_3]
2017-06-03 18:40:28 -07:00
Or, the wrapper can be constructed with a non-owning reference. In
this case, the caller is responsible for managing the lifetime of the
underlying socket being wrapped:
2017-06-07 16:30:49 -07:00
[ws_snippet_4]
2017-06-03 18:40:28 -07:00
Once the WebSocket stream wrapper is created, the wrapped object may be
2017-06-07 16:30:49 -07:00
accessed by calling
2017-07-23 22:49:57 -07:00
[link beast.ref.boost__beast__websocket__stream.next_layer.overload1 `stream::next_layer`]:
2017-06-07 16:30:49 -07:00
[ws_snippet_5]
2017-06-03 18:40:28 -07:00
[warning
Initiating operations on the next layer while websocket
operations are being performed may result in undefined behavior.
]
[endsect]