# ws::WebSocket

<a id="websocket"></a>

# WebSocket

```cpp
#include <websocket.h>

class WebSocket
```

Defined in src/http/include/icy/http/websocket.h:365

> **Inherits:** [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1)

Standalone [WebSocket](#websocket) class.

## List of all members

| Name | Kind | Owner |
|------|------|-------|
| [`WebSocket`](#websocket-1) | `function` | Declared here |
| [`~WebSocket`](#websocket-2) | `function` | Declared here |
| [`request`](#request) | `function` | Declared here |
| [`response`](#response) | `function` | Declared here |
| [`_request`](#_request-1) | `variable` | Declared here |
| [`_response`](#_response-1) | `variable` | Declared here |
| [`Vec`](#vec) | `typedef` | Declared here |
| [`WebSocketFramer`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketframer-3) | `friend` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`socket`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#socket) | `variable` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-2) | `function` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`send`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#send) | `function` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`send`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#send-1) | `function` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`sendOwned`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#sendowned) | `function` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`sendOwned`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#sendowned-1) | `function` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`shutdown`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#shutdown) | `function` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`sendClientRequest`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#sendclientrequest) | `function` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`handleClientResponse`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#handleclientresponse) | `function` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`handleServerRequest`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#handleserverrequest) | `function` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`onHandshakeComplete`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#onhandshakecomplete) | `function` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`framer`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#framer) | `variable` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`_request`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#_request) | `variable` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`_response`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#_response) | `variable` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`_closeState`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#_closestate) | `variable` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`~WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-3) | `function` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`sendControlFrame`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#sendcontrolframe) | `function` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`resetFrameState`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#resetframestate) | `function` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`onSocketConnect`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#onsocketconnect) | `function` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`onSocketRecv`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#onsocketrecv) | `function` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |
| [`onSocketClose`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#onsocketclose) | `function` | Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) |

## Inherited from [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1)

| Kind | Name | Description |
|------|------|-------------|
| `friend` | [`WebSocketFramer`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketframer-3)  |  |
| `variable` | [`socket`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#socket)  | Pointer to the underlying socket. Sent data will be proxied to this socket. |
| `function` | [`WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-2)  | Creates a [WebSocketAdapter](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-1) using the given socket, mode and HTTP message objects. |
| `function` | [`send`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#send) `virtual` `override` | Frames and sends data to the peer's address. |
| `function` | [`send`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#send-1) `virtual` `override` | Frames and sends data to a specific peer address (for UDP-backed sockets). |
| `function` | [`sendOwned`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#sendowned) `virtual` `override` |  |
| `function` | [`sendOwned`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#sendowned-1) `virtual` `override` |  |
| `function` | [`shutdown`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#shutdown) `virtual` | Sends a [WebSocket](#websocket) CLOSE frame with the given status code and message, then closes the underlying socket. |
| `function` | [`sendClientRequest`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#sendclientrequest) `virtual` | Client side. |
| `function` | [`handleClientResponse`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#handleclientresponse) `virtual` | Parses the server's HTTP upgrade response and completes the handshake. Any data remaining in the buffer after the HTTP response is re-fed as [WebSocket](#websocket) frames. |
| `function` | [`handleServerRequest`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#handleserverrequest) `virtual` | Server side. |
| `function` | [`onHandshakeComplete`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#onhandshakecomplete) `virtual` | Called when the [WebSocket](#websocket) handshake completes. Emits the connect event to downstream handlers. |
| `variable` | [`framer`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#framer)  |  |
| `variable` | [`_request`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#_request)  |  |
| `variable` | [`_response`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#_response)  |  |
| `variable` | [`_closeState`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#_closestate)  |  |
| `function` | [`~WebSocketAdapter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#websocketadapter-3) `virtual` |  |
| `function` | [`sendControlFrame`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#sendcontrolframe)  |  |
| `function` | [`resetFrameState`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#resetframestate)  |  |
| `function` | [`onSocketConnect`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#onsocketconnect) `virtual` `override` | Called by the socket on connect; initiates the client handshake. |
| `function` | [`onSocketRecv`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#onsocketrecv) `virtual` `override` | Called by the socket on each received buffer; handles handshake or frame parsing depending on state. |
| `function` | [`onSocketClose`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-http-ws-WebSocketAdapter.md#onsocketclose) `virtual` `override` | Called by the socket on close; resets framer state. |

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`WebSocket`](#websocket-1)  | Creates the [WebSocket](#websocket) with the given Socket. The Socket should be a TCPSocket or a SSLSocket, depending on the protocol used (ws or wss). |
|  | [`~WebSocket`](#websocket-2) `virtual` |  |
| `http::Request &` | [`request`](#request) `nodiscard` | Returns the HTTP request used during the [WebSocket](#websocket) handshake. |
| `http::Response &` | [`response`](#response) `nodiscard` | Returns the HTTP response received during the [WebSocket](#websocket) handshake. |

---

<a id="websocket-1"></a>

### WebSocket

```cpp
WebSocket(const net::Socket::Ptr & socket)
```

Defined in src/http/include/icy/http/websocket.h:373

Creates the [WebSocket](#websocket) with the given Socket. The Socket should be a TCPSocket or a SSLSocket, depending on the protocol used (ws or wss).

---

<a id="websocket-2"></a>

### ~WebSocket

`virtual`

```cpp
virtual ~WebSocket()
```

Defined in src/http/include/icy/http/websocket.h:375

---

<a id="request"></a>

### request

`nodiscard`

```cpp
[[nodiscard]] http::Request & request()
```

Defined in src/http/include/icy/http/websocket.h:378

Returns the HTTP request used during the [WebSocket](#websocket) handshake.

---

<a id="response"></a>

### response

`nodiscard`

```cpp
[[nodiscard]] http::Response & response()
```

Defined in src/http/include/icy/http/websocket.h:381

Returns the HTTP response received during the [WebSocket](#websocket) handshake.

## Protected Attributes

| Return | Name | Description |
|--------|------|-------------|
| `http::Request` | [`_request`](#_request-1)  |  |
| `http::Response` | [`_response`](#_response-1)  |  |

---

<a id="_request-1"></a>

### _request

```cpp
http::Request _request
```

Defined in src/http/include/icy/http/websocket.h:384

---

<a id="_response-1"></a>

### _response

```cpp
http::Response _response
```

Defined in src/http/include/icy/http/websocket.h:385

## Public Types

| Name | Description |
|------|-------------|
| [`Vec`](#vec)  |  |

---

<a id="vec"></a>

### Vec

```cpp
using Vec = std::vector< WebSocket >
```

Type: std::vector< [`WebSocket`](#websocket-1) >

Defined in src/http/include/icy/http/websocket.h:368
