# ws

<a id="ws"></a>

# ws

[WebSocket](https://auscaster.com/icey/docs/api-reference/icy-http-ws-WebSocket.md#websocket) framing, handshakes, and connection helpers.

## Classes

| Name | Description |
|------|-------------|
| [`ConnectionAdapter`](https://auscaster.com/icey/docs/api-reference/icy-http-ws-ConnectionAdapter.md#connectionadapter-4) | [WebSocket](https://auscaster.com/icey/docs/api-reference/icy-http-ws-WebSocket.md#websocket) class which belongs to an HTTP connection. |
| [`WebSocket`](https://auscaster.com/icey/docs/api-reference/icy-http-ws-WebSocket.md#websocket) | Standalone [WebSocket](https://auscaster.com/icey/docs/api-reference/icy-http-ws-WebSocket.md#websocket) class. |
| [`WebSocketAdapter`](https://auscaster.com/icey/docs/api-reference/icy-http-ws-WebSocketAdapter.md#websocketadapter) | [WebSocket](https://auscaster.com/icey/docs/api-reference/icy-http-ws-WebSocket.md#websocket) protocol adapter for both client and server endpoints. |
| [`WebSocketException`](https://auscaster.com/icey/docs/api-reference/icy-http-ws-WebSocketException.md#websocketexception) | A [WebSocket](https://auscaster.com/icey/docs/api-reference/icy-http-ws-WebSocket.md#websocket) error, carrying its error code and, where one applies, the close status code. |
| [`WebSocketFramer`](https://auscaster.com/icey/docs/api-reference/icy-http-ws-WebSocketFramer.md#websocketframer-1) | [WebSocket](https://auscaster.com/icey/docs/api-reference/icy-http-ws-WebSocket.md#websocket) frame encoder/decoder and handshake validator for RFC 6455. |

## Enumerations

| Name | Description |
|------|-------------|
| [`Mode`](#mode-2)  | [WebSocket](https://auscaster.com/icey/docs/api-reference/icy-http-ws-WebSocket.md#websocket) endpoint mode. |
| [`FrameFlags`](#frameflags)  | Frame header flags. |
| [`Opcode`](#opcode)  | Frame header opcodes. |
| [`SendFlags`](#sendflags)  | Combined header flags and opcodes for identifying the payload type of sent frames. |
| [`CloseStatusCode`](#closestatuscode)  | StatusCodes for CLOSE frames sent with shutdown(). |
| [`ErrorCode`](#errorcode)  | These error codes can be obtained from [WebSocket](https://auscaster.com/icey/docs/api-reference/icy-http-ws-WebSocket.md#websocket) exceptions to determine the exact cause of the error. |
| [`CloseState`](#closestate)  |  |

---

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

### Mode

```cpp
enum Mode
```

[Defined in src/http/include/icy/http/websocket.h:35](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/websocket.h#L35)

[WebSocket](https://auscaster.com/icey/docs/api-reference/icy-http-ws-WebSocket.md#websocket) endpoint mode.

| Value | Description |
|-------|-------------|
| `ServerSide` | Server-side [WebSocket](https://auscaster.com/icey/docs/api-reference/icy-http-ws-WebSocket.md#websocket). |
| `ClientSide` | Client-side [WebSocket](https://auscaster.com/icey/docs/api-reference/icy-http-ws-WebSocket.md#websocket). |

---

<a id="frameflags"></a>

### FrameFlags

```cpp
enum FrameFlags
```

[Defined in src/http/include/icy/http/websocket.h:43](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/websocket.h#L43)

Frame header flags.

| Value | Description |
|-------|-------------|
| `Fin` | FIN bit: final fragment of a multi-fragment message. |
| `Rsv1` | Reserved for future use. Must be zero. |
| `Rsv2` | Reserved for future use. Must be zero. |
| `Rsv3` | Reserved for future use. Must be zero. |

---

<a id="opcode"></a>

### Opcode

```cpp
enum Opcode
```

[Defined in src/http/include/icy/http/websocket.h:53](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/websocket.h#L53)

Frame header opcodes.

| Value | Description |
|-------|-------------|
| `Continuation` | Continuation frame. |
| `Text` | Text frame. |
| `Binary` | Binary frame. |
| `Close` | Close connection. |
| `Ping` | Ping frame. |
| `Pong` | Pong frame. |
| `Bitmask` | Bit mask for opcodes. |

---

<a id="sendflags"></a>

### SendFlags

```cpp
enum SendFlags
```

[Defined in src/http/include/icy/http/websocket.h:67](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/websocket.h#L67)

Combined header flags and opcodes for identifying the payload type of sent frames.

| Value | Description |
|-------|-------------|
| `Text` |  |
| `Binary` |  |

---

<a id="closestatuscode"></a>

### CloseStatusCode

```cpp
enum CloseStatusCode
```

[Defined in src/http/include/icy/http/websocket.h:75](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/websocket.h#L75)

StatusCodes for CLOSE frames sent with shutdown().

| Value | Description |
|-------|-------------|
| `NormalClose` |  |
| `EndpointGoingAway` |  |
| `ProtocolError` |  |
| `PayloadNotAcceptable` |  |
| `Reserved` |  |
| `ReservedNoStatusCode` |  |
| `ReservedAbnormalClose` |  |
| `MalformedPayload` |  |
| `PolicyViolation` |  |
| `PayloadTooBig` |  |
| `ExtensionRequired` |  |
| `UnexpectedCondition` |  |
| `ReservedTLSFailure` |  |

---

<a id="errorcode"></a>

### ErrorCode

```cpp
enum ErrorCode
```

[Defined in src/http/include/icy/http/websocket.h:95](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/websocket.h#L95)

These error codes can be obtained from [WebSocket](https://auscaster.com/icey/docs/api-reference/icy-http-ws-WebSocket.md#websocket) exceptions to determine the exact cause of the error.

| Value | Description |
|-------|-------------|
| `NoHandshake` | No [Connection](https://auscaster.com/icey/docs/api-reference/icy-http-Connection.md#connection-1): Upgrade or Upgrade: websocket header in handshake request. |
| `HandshakeNoVersion` | No Sec-WebSocket-Version header in handshake request. |
| `HandshakeUnsupportedVersion` | Unsupported [WebSocket](https://auscaster.com/icey/docs/api-reference/icy-http-ws-WebSocket.md#websocket) version requested by client. |
| `HandshakeNoKey` | No Sec-WebSocket-Key header in handshake request. |
| `HandshakeAccept` | No Sec-WebSocket-Accept header or wrong value. |
| `Unauthorized` | The server rejected the username or password for authentication. |
| `PayloadTooBig` | Payload too big for supplied buffer. |
| `IncompleteFrame` | Incomplete frame received. |
| `InvalidRsvBits` | RSV bits set without extension negotiation. |
| `InvalidOpcode` | Unknown or reserved opcode received. |
| `UnmaskedClientFrame` | Client-to-server frame not masked (RFC 6455 violation). |
| `ProtocolViolation` | General RFC 6455 protocol violation. |

---

<a id="closestate"></a>

### CloseState

```cpp
enum CloseState
```

[Defined in src/http/include/icy/http/websocket.h:112](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/websocket.h#L112)

| Value | Description |
|-------|-------------|
| `Open` |  |
| `CloseSent` |  |
| `CloseReceived` |  |
| `Closed` |  |
## Variables

| Return | Name | Description |
|--------|------|-------------|
| `constexpr auto` | [`ServerSide`](#serverside) `static` `constexpr` |  |
| `constexpr auto` | [`ClientSide`](#clientside) `static` `constexpr` |  |
| `constexpr char` | [`ProtocolGuid`](#protocolguid) `constexpr` |  |
| `constexpr char` | [`ProtocolVersion`](#protocolversion) `constexpr` | The [WebSocket](https://auscaster.com/icey/docs/api-reference/icy-http-ws-WebSocket.md#websocket) protocol version supported (13). |

---

<a id="serverside"></a>

### ServerSide

`static` `constexpr`

```cpp
constexpr auto ServerSide = Mode::ServerSide
```

[Defined in src/http/include/icy/http/websocket.h:143](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/websocket.h#L143)

---

<a id="clientside"></a>

### ClientSide

`static` `constexpr`

```cpp
constexpr auto ClientSide = Mode::ClientSide
```

[Defined in src/http/include/icy/http/websocket.h:144](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/websocket.h#L144)

---

<a id="protocolguid"></a>

### ProtocolGuid

`constexpr`

```cpp
constexpr char ProtocolGuid[]
```

[Defined in src/http/include/icy/http/websocket.h:146](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/websocket.h#L146)

---

<a id="protocolversion"></a>

### ProtocolVersion

`constexpr`

```cpp
constexpr char ProtocolVersion[]
```

[Defined in src/http/include/icy/http/websocket.h:149](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/websocket.h#L149)

The [WebSocket](https://auscaster.com/icey/docs/api-reference/icy-http-ws-WebSocket.md#websocket) protocol version supported (13).
