[/
    Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)

    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)

    Official repository: https://github.com/boostorg/beast
]

[section 示例]
[block'''<?dbhtml stop-chunking?>''']

这些程序的源码和编译脚本存放在 [path_link example example] 目录里。

[/-----------------------------------------------------------------------------]

[section 客户端]

这些 HTTP 客户端会向命令行指定的服务器发送 GET 请求，并输出返回结果。爬取客户端会异步抓取排名前 10000 的站点的文档根目录，可用于评估程序的健壮性。所有异步客户端都支持超时设置。

[table
[[Description] [Source File] [Source File (using SSL)]]
[
        [HTTP 同步]
        [[path_link example/http/client/sync/http_client_sync.cpp http_client_sync.cpp]]
        [[path_link example/http/client/sync-ssl/http_client_sync_ssl.cpp http_client_sync_ssl.cpp]]
][
        [HTTP 异步]
        [[path_link example/http/client/async/http_client_async.cpp http_client_async.cpp]]
        [[path_link example/http/client/async-ssl/http_client_async_ssl.cpp http_client_async_ssl.cpp]]
][
        [HTTP 异步 Unix 域套接字]
        [[path_link example/http/client/async-local/http_client_async_local.cpp http_client_async_local.cpp]]
        []
][
        [使用 __system_executor__ 的 HTTP 异步模式]
        []
        [[path_link example/http/client/async-ssl-system-executor/http_client_async_ssl_system_executor.cpp http_client_async_ssl_system_executor.cpp]]
][
        [HTTP 协程]
        [[path_link example/http/client/coro/http_client_coro.cpp http_client_coro.cpp]]
        [[path_link example/http/client/coro-ssl/http_client_coro_ssl.cpp http_client_coro_ssl.cpp]]
][
        [HTTP C++20 协程]
        [[path_link example/http/client/awaitable/http_client_awaitable.cpp http_client_awaitable.cpp]]
        [[path_link example/http/client/awaitable-ssl/http_client_awaitable_ssl.cpp http_client_awaitable_ssl.cpp]]
][
        [HTTP 爬取（异步）]
        [[path_link example/http/client/crawl/http_crawl.cpp http_crawl.cpp]]
        []
][
        [HTTP json_body（同步）]
        [
                [path_link example/http/client/body/json_body.hpp json_body.hpp]
                [path_link example/http/client/body/json_client.cpp json_client.cpp]
        ]
        []
][
        [HTTP client for all methods (synchronous)]
        [[path_link example/http/client/methods/http_client_methods.cpp http_client_methods.cpp]]
        []
]]

这些 WebSocket 客户端会先连接服务器，发一条消息，收到回复后打印结果，最后断开连接。所有异步客户端都支持设置超时时间。

[table
[[Description] [Source File] [Source File (using SSL)]]
[
        [WebSocket 同步]
        [[path_link example/websocket/client/sync/websocket_client_sync.cpp websocket_client_sync.cpp]]
        [[path_link example/websocket/client/sync-ssl/websocket_client_sync_ssl.cpp websocket_client_sync_ssl.cpp]]
][
        [WebSocket 异步]
        [[path_link example/websocket/client/async/websocket_client_async.cpp websocket_client_async.cpp]]
        [[path_link example/websocket/client/async-ssl/websocket_client_async_ssl.cpp websocket_client_async_ssl.cpp]]
][
        [WebSocket 异步 Unix 域套接字]
        [[path_link example/websocket/client/async-local/websocket_client_async_local.cpp websocket_client_async_local.cpp]]
        []
][
        [使用 __system_executor__ 的 WebSocket 异步模式]
        []
        [[path_link example/websocket/client/async-ssl-system-executor/websocket_client_async_ssl_system_executor.cpp websocket_client_async_ssl_system_executor.cpp]]
][
        [WebSocket 协程]
        [[path_link example/websocket/client/coro/websocket_client_coro.cpp websocket_client_coro.cpp]]
        [[path_link example/websocket/client/coro-ssl/websocket_client_coro_ssl.cpp websocket_client_coro_ssl.cpp]]
][
        [WebSocket C++20 协程]
        [[path_link example/websocket/client/awaitable/websocket_client_awaitable.cpp websocket_client_awaitable.cpp]]
        []
]]

[endsect]

[/-----------------------------------------------------------------------------]

[section 服务器端]

这些 HTTP 服务器会从命令行指定的根目录中读取文件并提供给客户端。所有异步服务器都支持设置超时时间。

[table
[[Description] [Source File] [Source File (using SSL)]]
[
        [HTTP 同步]
        [[path_link example/http/server/sync/http_server_sync.cpp http_server_sync.cpp]]
        [[path_link example/http/server/sync-ssl/http_server_sync_ssl.cpp http_server_sync_ssl.cpp]]
][
        [HTTP 异步]
        [[path_link example/http/server/async/http_server_async.cpp http_server_async.cpp]]
        [[path_link example/http/server/async-ssl/http_server_async_ssl.cpp http_server_async_ssl.cpp]]
][
        [HTTP 异步 Unix 域套接字]
        [[path_link example/http/server/async-local/http_server_async_local.cpp http_server_async_local.cpp]]
        []
][
        [HTTP 协程]
        [[path_link example/http/server/coro/http_server_coro.cpp http_server_coro.cpp]]
        [[path_link example/http/server/coro-ssl/http_server_coro_ssl.cpp http_server_coro_ssl.cpp]]
][
        [HTTP 无栈协程]
        [[path_link example/http/server/stackless/http_server_stackless.cpp http_server_stackless.cpp]]
        [[path_link example/http/server/stackless-ssl/http_server_stackless_ssl.cpp http_server_stackless_ssl.cpp]]
][
        [HTTP C++20 协程]
        [[path_link example/http/server/awaitable/http_server_awaitable.cpp http_server_awaitable.cpp]]
][
        [HTTP 快速模式（速度优先）]
        [[path_link example/http/server/fast/http_server_fast.cpp http_server_fast.cpp]]
        []
][
        [HTTP 精简模式（空间优先）]
        [[path_link example/http/server/small/http_server_small.cpp http_server_small.cpp]]
        []
][
        [HTTP 灵活模式（普通 + SSL）]
        []
        [[path_link example/http/server/flex/http_server_flex.cpp http_server_flex.cpp]]
]]

这些 WebSocket 服务器会把收到的任何消息原样返回，并且保持会话不断开，直到客户端主动断开为止。所有异步服务器都支持设置超时时间。

[table
[[Description] [Source File] [Source File (using SSL)]]
[
        [WebSocket 同步]
        [[path_link example/websocket/server/sync/websocket_server_sync.cpp websocket_server_sync.cpp]]
        [[path_link example/websocket/server/sync-ssl/websocket_server_sync_ssl.cpp websocket_server_sync_ssl.cpp]]
][
        [WebSocket 异步]
        [[path_link example/websocket/server/async/websocket_server_async.cpp websocket_server_async.cpp]]
        [[path_link example/websocket/server/async-ssl/websocket_server_async_ssl.cpp websocket_server_async_ssl.cpp]]
][
        [WebSocket 异步 Unix 域套接字]
        [[path_link example/websocket/server/async-local/websocket_server_async_local.cpp websocket_server_async_local.cpp]]
        []
][
        [WebSocket 协程]
        [[path_link example/websocket/server/coro/websocket_server_coro.cpp websocket_server_coro.cpp]]
        [[path_link example/websocket/server/coro-ssl/websocket_server_coro_ssl.cpp websocket_server_coro_ssl.cpp]]
][
        [WebSocket 无栈协程]
        [[path_link example/websocket/server/stackless/websocket_server_stackless.cpp websocket_server_stackless.cpp]]
        [[path_link example/websocket/server/stackless-ssl/websocket_server_stackless_ssl.cpp websocket_server_stackless_ssl.cpp]]
][
        [WebSocket C++20 协程]
        [[path_link example/websocket/server/awaitable/websocket_server_awaitable.cpp websocket_server_awaitable.cpp]]
        []
][
        [WebSocket 快速模式（适用于基准测试）]
        [[path_link example/websocket/server/fast/websocket_server_fast.cpp websocket_server_fast.cpp]]
        []
]]

[endsect]

[/-----------------------------------------------------------------------------]

[section 服务器端（进阶篇）]

这些服务器在同一端口上同时提供 HTTP 和 WebSocket 服务，并展示了高级功能的实现方式。

[table
[[Description] [Features] [Sources]]
[
        [进阶篇]
        [[itemized_list
            [Timeouts]
            [Multi-threaded]
            [HTTP pipelining]
            [Parser-oriented HTTP reading]
            [Dual protocols: HTTP and WebSocket]
            [Clean exit via SIGINT (CTRL+C) or SIGTERM (kill)]
        ]]
        [[path_link example/advanced/server/advanced_server.cpp advanced_server.cpp]]
][
        [进阶篇，灵活模式（普通 + SSL）]
        [[itemized_list
            [Timeouts]
            [Multi-threaded]
            [HTTP pipelining]
            [Parser-oriented HTTP reading]
            [Dual protocols: HTTP and WebSocket]
            [Flexible ports: plain and SSL on the same port]
            [Clean exit via SIGINT (CTRL+C) or SIGTERM (kill)]
        ]]
        [[path_link example/advanced/server-flex/advanced_server_flex.cpp advanced_server_flex.cpp]]
][
         [进阶篇，灵活模式（普通 + SSL）支持可等待操作]
         [[itemized_list
             [Timeouts]
             [Multi-threaded]
             [HTTP pipelining]
             [Parser-oriented HTTP reading]
             [Dual protocols: HTTP and WebSocket]
             [Flexible ports: plain and SSL on the same port]
             [Clean exit via SIGINT (CTRL+C) or SIGTERM (kill)]
             [Usage of cancellation_signals]
         ]]
         [[path_link example/advanced/server-flex-awaitable/advanced_server_flex_awaitable.cpp advanced_server_flex_awaitable.cpp]]
 ][
        [聊天服务器，多线程版]
        [[itemized_list
            [Multi-threaded]
            [Broadcasting Messages]
            [Multi-user Chat Server]
            [JavaScript Browser Client]
            [Parser-oriented HTTP reading]
            [Dual protocols: HTTP and WebSocket]
            [Clean exit via SIGINT (CTRL+C) or SIGTERM (kill)]
        ]]
        [[path_link example/websocket/server/chat-multi chat-multi]]
]]

[endsect]

[/-----------------------------------------------------------------------------]

[section:chat_server 聊天服务器 __视频__]

这个示例展示了一个 WebSocket 聊天服务器，支持多个用户同时连接并参与实时群聊。它附带了一个用 JavaScript 和 HTML5 实现的小型前端界面，可以在任意浏览器中运行。该示例还配有一小时的演讲视频，内容包括网络概念讲解，以及客户端和服务器实现细节的深度剖析。该演讲于 [@https://cppcon.org CppCon 2018] 上发布。Beast 示例中的源码相比原始程序有所改进。

[table WebSocket 聊天服务器与 JavaScript 客户端
[[组件] [特性] [源码]]
[
  [服务器]
  [[itemized_list
      [C++]
      [Timeouts]
      [Multi-threaded]
      [Broadcast to multiple peers]
      [Dual protocols: HTTP and WebSocket]
      [Clean exit via SIGINT (CTRL+C) or SIGTERM (kill)]
  ]]
  [[path_link example/websocket/server/chat-multi chat-multi]]
][
  [客户端]
  [[itemized_list
      [JavaScript / HTML5]
      [Runs in the browser]
      [Delivered by the server]
      [Only 60 lines total including UI]
      [Completely portable graphics]
  ]]
  [[path_link example/websocket/server/chat-multi/chat_client.html chat_client.html]]
]]

[/ "Get rich quick! Using Boost.Beast WebSockets and Networking TS"]
'''
<mediaobject>
  <videoobject>
    <videodata fileref="https://www.youtube.com/embed/7FQwAjELMek"
        align="center" contentwidth="560" contentdepth="315"/>
  </videoobject>
</mediaobject>
'''

[endsect]

[/-----------------------------------------------------------------------------]

[endsect]
