Files
boost_beast/doc/qbk/02_examples.qbk

292 lines
9.7 KiB
Plaintext
Raw Normal View History

2016-09-25 11:19:51 -04:00
[/
2017-07-28 19:32:33 -07:00
Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
2016-09-25 11:19:51 -04: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
2016-09-25 11:19:51 -04:00
]
Refactor chunked-encoding serialization: New buffer sequence classes are provided to allow full control over the serialization of chunk-encoded message payloads: * chunk_header A ConstBufferSequence representing the chunk header. It includes a hexadecimal-encoded size, an optional set of chunk extensions, and the trailing CRLF required to denote the end of the chunk header. This allows the caller to manually serialize the chunk body in one or more calls to a stream output function. The caller must also output an object of type `chunk_crlf` to the stream to indicate the end of the chunk body. * chunk_crlf A small ConstBufferSequence that simply represents the two character sequence "\r\n" (CRLF). This is needed for the case where the caller wants to output a chunk body as a series of buffers (i.e. "chunking a chunk"). * chunk_body A ConstBufferSequence representing a complete chunk. This includes the size, an optional set of chunk extensions, a caller provided buffer containing the body, and the required CRLF that follows. * chunk_final A ConstBufferSequence representing a final chunk. It includes an optional set of caller-provided field trailers * chunk_extensions A container for building a set of chunk extensions to use during serialization. The use of the container is optional, callers may provide their own buffer containing a correctly formatted set of chunk extensions, or they may use their own convenience container which meets the requirements. The basic_fields container is modified to allow construction outside the context of a message. The container can be used to provide trailers to `chunk_final`. Actions Required: * Remove references to ChunkDecorators. Use the new chunk-encoding buffer sequences to manually produce a chunked payload body in the case where control over the chunk-extensions and/or trailers is required.
2017-07-09 20:09:30 -07:00
[section Quick Start]
[block'''<?dbhtml stop-chunking?>''']
2016-09-25 11:19:51 -04:00
2017-06-19 20:03:05 -07:00
These complete programs are intended to quickly impress upon readers
the flavor of the library. Source code and build scripts for them are
2017-10-26 16:05:50 -07:00
located in the [source_file example] directory.
2017-06-19 20:03:05 -07:00
[section HTTP Client]
2016-09-25 11:19:51 -04:00
2017-06-04 17:25:55 -07:00
Use HTTP to make a GET request to a website and print the response:
2017-10-26 16:05:50 -07:00
File: [source_file example/http/client/sync/http_client_sync.cpp]
[example_http_client]
[endsect]
2017-06-04 17:25:55 -07:00
2017-06-16 19:27:00 -07:00
[section WebSocket Client]
2017-06-04 17:25:55 -07:00
2017-06-16 19:27:00 -07:00
Establish a WebSocket connection, send a message and receive the reply:
2016-09-25 11:19:51 -04:00
2017-10-26 16:05:50 -07:00
File: [source_file example/websocket/client/sync/websocket_client_sync.cpp]
2017-06-04 17:25:55 -07:00
2017-06-16 19:27:00 -07:00
[example_websocket_client]
2017-06-16 19:27:00 -07:00
[endsect]
[endsect]
2017-06-04 17:25:55 -07:00
2016-09-25 11:19:51 -04:00
Refactor chunked-encoding serialization: New buffer sequence classes are provided to allow full control over the serialization of chunk-encoded message payloads: * chunk_header A ConstBufferSequence representing the chunk header. It includes a hexadecimal-encoded size, an optional set of chunk extensions, and the trailing CRLF required to denote the end of the chunk header. This allows the caller to manually serialize the chunk body in one or more calls to a stream output function. The caller must also output an object of type `chunk_crlf` to the stream to indicate the end of the chunk body. * chunk_crlf A small ConstBufferSequence that simply represents the two character sequence "\r\n" (CRLF). This is needed for the case where the caller wants to output a chunk body as a series of buffers (i.e. "chunking a chunk"). * chunk_body A ConstBufferSequence representing a complete chunk. This includes the size, an optional set of chunk extensions, a caller provided buffer containing the body, and the required CRLF that follows. * chunk_final A ConstBufferSequence representing a final chunk. It includes an optional set of caller-provided field trailers * chunk_extensions A container for building a set of chunk extensions to use during serialization. The use of the container is optional, callers may provide their own buffer containing a correctly formatted set of chunk extensions, or they may use their own convenience container which meets the requirements. The basic_fields container is modified to allow construction outside the context of a message. The container can be used to provide trailers to `chunk_final`. Actions Required: * Remove references to ChunkDecorators. Use the new chunk-encoding buffer sequences to manually produce a chunked payload body in the case where control over the chunk-extensions and/or trailers is required.
2017-07-09 20:09:30 -07:00
[section Examples]
2017-06-16 19:27:00 -07:00
[block'''<?dbhtml stop-chunking?>''']
2017-06-19 20:03:05 -07:00
Source code and build scripts for these programs are located
2017-10-26 16:05:50 -07:00
in the [source_file example] directory.
[template example_src[path name] '''<ulink url="../../'''[path]'''">'''[name]'''</ulink>''']
2017-08-08 06:20:24 -07:00
[section Clients]
These HTTP clients submit a GET request to a server specified on the command
line, and prints the resulting response. The crawl client asynchronously
fetches the document root of the 10,000 top ranked domains, this may be
used to evaluate robustness.
[table
[[Description] [Source File] [Source File (using SSL)]]
[
[HTTP, synchronous]
[[example_src example/http/client/sync/http_client_sync.cpp http_client_sync.cpp]]
[[example_src example/http/client/sync-ssl/http_client_sync_ssl.cpp http_client_sync_ssl.cpp]]
][
[HTTP, asynchronous]
[[example_src example/http/client/async/http_client_async.cpp http_client_async.cpp]]
[[example_src example/http/client/async-ssl/http_client_async_ssl.cpp http_client_async_ssl.cpp]]
][
[HTTP, coroutine]
[[example_src example/http/client/coro/http_client_coro.cpp http_client_coro.cpp]]
[[example_src example/http/client/coro-ssl/http_client_coro_ssl.cpp http_client_coro_ssl.cpp]]
][
[HTTP crawl (asynchronous)]
[[example_src example/http/client/crawl/http_crawl.cpp http_crawl.cpp]]
[]
]]
These WebSocket clients connect to a
server and send a message, then receive a message and print the response
before disconnecting.
[table
[[Description] [Source File] [Source File (using SSL)]]
[
[WebSocket, synchronous]
[[example_src example/websocket/client/sync/websocket_client_sync.cpp websocket_client_sync.cpp]]
[[example_src example/websocket/client/sync-ssl/websocket_client_sync_ssl.cpp websocket_client_sync_ssl.cpp]]
][
[WebSocket, asynchronous]
[[example_src example/websocket/client/async/websocket_client_async.cpp websocket_client_async.cpp]]
[[example_src example/websocket/client/async-ssl/websocket_client_async_ssl.cpp websocket_client_async_ssl.cpp]]
][
[WebSocket, coroutine]
[[example_src example/websocket/client/coro/websocket_client_coro.cpp websocket_client_coro.cpp]]
[[example_src example/websocket/client/coro-ssl/websocket_client_coro_ssl.cpp websocket_client_coro_ssl.cpp]]
]]
2017-08-08 06:20:24 -07:00
[endsect]
[section Servers]
These HTTP servers deliver files from a root directory specified on the
command line.
[table
[[Description] [Source File] [Source File (using SSL)]]
[
[HTTP, synchronous]
[[example_src example/http/server/sync/http_server_sync.cpp http_server_sync.cpp]]
[[example_src example/http/server/sync-ssl/http_server_sync_ssl.cpp http_server_sync_ssl.cpp]]
][
[HTTP, asynchronous]
[[example_src example/http/server/async/http_server_async.cpp http_server_async.cpp]]
[[example_src example/http/server/async-ssl/http_server_async_ssl.cpp http_server_async_ssl.cpp]]
][
[HTTP, coroutine]
[[example_src example/http/server/coro/http_server_coro.cpp http_server_coro.cpp]]
[[example_src example/http/server/coro-ssl/http_server_coro_ssl.cpp http_server_coro_ssl.cpp]]
][
[HTTP, stackless coroutine]
[[example_src example/http/server/stackless/http_server_stackless.cpp http_server_stackless.cpp]]
[[example_src example/http/server/stackless-ssl/http_server_stackless_ssl.cpp http_server_stackless_ssl.cpp]]
][
[HTTP, fast (optimized for speed)]
[[example_src example/http/server/fast/http_server_fast.cpp http_server_fast.cpp]]
[]
][
[HTTP, small (optimized for space)]
[[example_src example/http/server/small/http_server_small.cpp http_server_small.cpp]]
[]
][
[HTTP, flex (plain + SSL)]
[]
[[example_src example/http/server/flex/http_server_flex.cpp http_server_flex.cpp]]
]]
These WebSocket servers echo back any message received, keeping the
session open until the client disconnects.
[table
[[Description] [Source File] [Source File (using SSL)]]
[
[WebSocket, synchronous]
[[example_src example/websocket/server/sync/websocket_server_sync.cpp websocket_server_sync.cpp]]
[[example_src example/websocket/server/sync-ssl/websocket_server_sync_ssl.cpp websocket_server_sync_ssl.cpp]]
][
[WebSocket, asynchronous]
[[example_src example/websocket/server/async/websocket_server_async.cpp websocket_server_async.cpp]]
[[example_src example/websocket/server/async-ssl/websocket_server_async_ssl.cpp websocket_server_async_ssl.cpp]]
][
[WebSocket, coroutine]
[[example_src example/websocket/server/coro/websocket_server_coro.cpp websocket_server_coro.cpp]]
[[example_src example/websocket/server/coro-ssl/websocket_server_coro_ssl.cpp websocket_server_coro_ssl.cpp]]
][
[WebSocket, stackless coroutine]
[[example_src example/websocket/server/stackless/websocket_server_stackless.cpp websocket_server_stackless.cpp]]
[[example_src example/websocket/server/stackless-ssl/websocket_server_stackless_ssl.cpp websocket_server_stackless_ssl.cpp]]
][
[WebSocket, fast (suited for benchmarks)]
[[example_src example/websocket/server/fast/websocket_server_fast.cpp websocket_server_fast.cpp]]
[]
]]
2017-08-08 06:20:24 -07:00
[endsect]
[section Servers (Advanced)]
These servers offer both HTTP and WebSocket services on the same port,
and illustrate the implementation of advanced features.
[table
[[Description] [Features] [Source File]]
[
[Advanced]
[[itemized_list
[HTTP pipelining]
[Asynchronous timeouts]
2017-12-15 09:00:44 -08:00
[Dual protocols: HTTP and WebSocket]
[WebSocket use idle ping for timeout]
[Clean exit via SIGINT (CTRL+C) or SIGTERM (kill)]
]]
[[example_src example/advanced/server/advanced_server.cpp advanced_server.cpp]]
][
[Advanced, flex (plain + SSL)]
[[itemized_list
[HTTP pipelining]
[Asynchronous timeouts]
[Dual protocols: HTTP and WebSocket]
2017-12-15 09:00:44 -08:00
[WebSocket use idle ping for timeout]
[Flexible ports: plain and SSL on the same port]
[Clean exit via SIGINT (CTRL+C) or SIGTERM (kill)]
]]
[[example_src example/advanced/server-flex/advanced_server_flex.cpp advanced_server_flex.cpp]]
]]
2017-08-08 06:20:24 -07:00
[endsect]
[section CppCon 2018]
This talk was given at [@https://cppcon.org CppCon 2018]. In this
presentation, we develop a multi-user chat server written in C++ using
Beast WebSocket, which uses a provided chat client written in HTML and
JavaScript. The source files for this example are located at
[source_file example/cppcon2018].
[block'''
<mediaobject>
<videoobject>
<videodata fileref="https://www.youtube.com/embed/7FQwAjELMek"
align="center" contentwidth="560" contentdepth="315"/>
</videoobject>
</mediaobject>
''']
[endsect]
2017-08-08 06:20:24 -07:00
[section Common Files]
Some of the examples use one or more shared header files, they are
listed here along with a description of their use:
[table
[[Source File] [Description]]
[
2017-10-26 16:05:50 -07:00
[[source_file example/common/detect_ssl.hpp]]
[
This contains the detect SSL algorithm including the
synchronous and asynchronous initiating functions, described
in the documentation. It is used by the "flex" servers which
support both plain and SSL sessions on the same port.
]
][
2017-10-26 16:05:50 -07:00
[[source_file example/common/root_certificates.hpp]]
[
This contains the root SSL certificates used in the SSL client
examples. These certificates are used to verify the signatures
of SSL certificates presented by remote servers. They represent
a subset of the public keys usually installed as part of the
operating system or browser, so they may not identify every
possible server.
]
][
2017-10-26 16:05:50 -07:00
[[source_file example/common/server_certificate.hpp]]
[
This file contains a self-signed SSL certificate used by the
SSL server examples. It has not been validated by a Certificate
Authority ("CA") so connecting to an example HTTP server using
a browser may generate security warnings.
]
]]
2017-07-02 18:22:36 -07:00
2017-08-08 06:20:24 -07:00
[endsect]
2017-07-02 18:22:36 -07:00
2017-06-16 19:27:00 -07:00
[section Documentation Samples]
2016-09-25 11:19:51 -04:00
2017-06-16 19:27:00 -07:00
Here are all of the example functions and classes presented
throughout the documentation, they can be included and used
in your program without modification
2016-09-25 11:19:51 -04:00
2017-10-26 16:05:50 -07:00
* [source_file example/doc/http_examples.hpp]
[endsect]
2016-09-25 11:19:51 -04:00
[section Composed Operations]
This program shows how to use Beast's network foundations to build a
composable asynchronous initiation function with associated composed
operation implementation. This is a complete, runnable version of
the example described in
[link beast.using_io.writing_composed_operations.echo Writing Composed Operations: Echo].
2017-10-26 16:05:50 -07:00
* [source_file example/echo-op/echo_op.cpp]
[endsect]
2017-06-11 09:59:13 -07:00
2016-09-25 11:19:51 -04:00
[endsect]