| Home | Libraries | People | FAQ | More

###### websocket::stream::accept (3 of 6 overloads)

Read and respond to a WebSocket HTTP Upgrade request.

###### Synopsis

    template<
        class ConstBufferSequence>
    void
    accept(
        ConstBufferSequence const& buffers);

###### Description

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 request is received and the response is sent.
- An error occurs.

The algorithm, known as a composed operation, is implemented in terms of calls to the next layer's `read_some` and `write_some` functions.

If a valid upgrade request is received, an HTTP response with a status-code of `beast::http::status::switching_protocols` is sent to the peer, otherwise a non-successful error is associated with the operation.

If the request size exceeds the capacity of the stream's internal buffer, the error `error::buffer_overflow` will be indicated. To handle larger requests, an application should read the HTTP request directly using `http::read` and then pass the request to the appropriate overload of `accept` or `async_accept`

###### Parameters

Name | Description
--- | ---
`buffers` | Caller provided data that has already been received on the stream. The implementation will copy the caller provided data before the function returns.

###### Exceptions

Type | Thrown On
--- | ---
`system_error` | Thrown on failure.

###### See Also

- Websocket Opening Handshake Server Requirements (RFC6455)