| 29 | #include "websocket_common.ipp" |
| 30 | |
| 31 | void |
| 32 | snippets() |
| 33 | { |
| 34 | { |
| 35 | //[code_websocket_1f |
| 36 | |
| 37 | // This newly constructed WebSocket stream will use the specified |
| 38 | // I/O context and have support for the permessage-deflate extension. |
| 39 | |
| 40 | stream<tcp_stream> ws(ioc); |
| 41 | |
| 42 | //] |
| 43 | } |
| 44 | |
| 45 | { |
| 46 | //[code_websocket_2f |
| 47 | |
| 48 | // The `tcp_stream` will be constructed with a new |
| 49 | // strand which uses the specified I/O context. |
| 50 | |
| 51 | stream<tcp_stream> ws(net::make_strand(ioc)); |
| 52 | |
| 53 | //] |
| 54 | } |
| 55 | |
| 56 | { |
| 57 | //[code_websocket_3f |
| 58 | |
| 59 | // Ownership of the `tcp_stream` is transferred to the websocket stream |
| 60 | |
| 61 | stream<tcp_stream> ws(std::move(sock)); |
| 62 | |
| 63 | //] |
| 64 | } |
| 65 | |
| 66 | { |
| 67 | stream<tcp_stream> ws(ioc); |
| 68 | //[code_websocket_4f |
| 69 | |
| 70 | // Calls `close` on the underlying `beast::tcp_stream` |
| 71 | ws.next_layer().close(); |
| 72 | |
| 73 | //] |
| 74 | } |
| 75 | |
| 76 | { |
| 77 | //[code_websocket_5f |
| 78 | |
| 79 | // The WebSocket stream will use SSL and a new strand |
| 80 | stream<net::ssl::stream<tcp_stream>> wss(net::make_strand(ioc), ctx); |
| 81 | |
| 82 | //] |
| 83 | |
| 84 | //[code_websocket_6f |
| 85 | |
| 86 | // Perform the SSL handshake in the client role |
| 87 | wss.next_layer().handshake(net::ssl::stream_base::client); |
| 88 | |