| Home | Libraries | People | FAQ | More

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

Send a websocket close control frame.

<h7> Synopsis </h7>

    void
    close(
        close_reason const& cr);

<h7> Description </h7>

This function is used to send a close frame, which begins the websocket closing handshake. The session ends when both ends of the connection have sent and received a close frame. The call blocks until one of the following conditions is true:

- The close frame is written.
- An error occurs.

The algorithm, known as a composed operation, is implemented in terms of calls to the next layer's `write_some` function. After beginning the closing handshake, the program should not write further message data, pings, or pongs. Instead, the program should continue reading message data until an error occurs. A read returning `websocket::closed` indicates a successful connection closure.

<h7> Parameters </h7>

Name | Description
--- | ---
`cr` | The reason for the close. If the close reason specifies a close code other than beast::websocket::close_code::none, the close frame is sent with the close code and optional reason string. Otherwise, the close frame is sent with no payload.

<h7> Exceptions </h7>

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

<h7> See Also </h7>

- Websocket Closing Handshake (RFC6455)