Beast Logo

PrevUpHomeNext

websocket::stream::async_handshake

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

template<
    class HandshakeHandler>
void-or-deduced
async_handshake(
    boost::string_ref const& host,
    boost::string_ref const& resource,
    HandshakeHandler&& h);

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:

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

host

The name of the remote host, required by the HTTP protocol. Copies may be made as needed.

resource

The requesting URI, which may not be empty, required by the HTTP protocol. Copies may be made as needed.

h

The handler to be called when the request completes. Copies will be made of the handler as required. The equivalent function signature of the handler must be:

 void handler(
    error_code const& error // 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_service::post.


PrevUpHomeNext