| Home | Libraries | People | FAQ | More

###### websocket::stream::async_handshake (1 of 2 overloads)

Start an asynchronous operation to send an upgrade request and receive the response.

Synopsis

    template<
        class HandshakeHandler>
    DEDUCED
    async_handshake(
        string_view host,
        string_view target,
        HandshakeHandler&& handler);

Description

This function is used to asynchronously send the HTTP WebSocket upgrade request and receive the HTTP WebSocket Upgrade response. This function call always returns immediately. The asynchronous operation will continue until one of the following conditions is true:

- The request is sent and the response is received.
- An error occurs on the stream

This operation is implemented in terms of one or more calls to the next layer's `async_read_some` and `async_write_some` functions, and is known as a composed operation. The program must ensure that the stream performs no other operations until this operation completes.

The operation is successful if the received HTTP response indicates a successful HTTP Upgrade (represented by a Status-Code of 101, "switching protocols").

Parameters

Name | Description
--- | ---
`host` | The name of the remote host, required by the HTTP protocol. Copies may be made as needed.
`target` | The Request Target, which may not be empty, required by the HTTP protocol. Copies of this parameter may be made as needed.
`handler` | Invoked when the operation completes. The handler may be moved or copied as needed. The equivalent function signature of the handler must be:
     void handler(
        error_code const& ec    // Result of operation
    );
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using `boost::asio::io_context::post`.