...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Perform the WebSocket handshake in the client role.
void handshake( response_type& res, string_view host, string_view target, error_code& ec);
This function is used to perform the WebSocket handshake, required before messages can be sent and received. During the handshake, the client sends the Websocket Upgrade HTTP request, and the server replies with an HTTP response indicating the result of the handshake.
The call blocks until one of the following conditions is true:
The algorithm, known as a composed operation, is
implemented in terms of calls to the next layer's read_some
and write_some
functions.
The handshake is successful if the received HTTP response indicates the
upgrade was accepted by the server, represented by a status-code
of beast::http::status::switching_protocols
.
Name |
Description |
---|---|
|
The HTTP Upgrade response returned by the remote endpoint. The caller may use the response to access any additional information sent by the server. |
|
The name of the remote host. This is required by the HTTP protocol to set the "Host" header field. |
|
The request-target, in origin-form. The server may use the target to distinguish different services on the same listening port. |
|
Set to indicate what error occurred, if any. |
error_code ec; response_type res; ws.handshake(res, "localhost" , "/" , ec); if (! ec) std::cout << res;