Source: https://h2corn.monicz.dev/api/websockets/

# WebSocket scope and messages

Use these mappings for a WebSocket scope and the events exchanged during its connection, data transfer, close, or HTTP response phase.

## WebSocketScope

Bases: `TypedDict`

A WebSocket scope in [`Scope`](https://h2corn.monicz.dev/api/applications/#h2corn.Scope "Scope module-attribute").

### type`instance-attribute`

```python
type: Literal['websocket']
```

### asgi`instance-attribute`

```python
asgi: HTTPASGIVersions
```

### http\_version`instance-attribute`

```python
http_version: Literal['1.1', '2']
```

### scheme`instance-attribute`

```python
scheme: str
```

### path`instance-attribute`

```python
path: str
```

### raw\_path`instance-attribute`

```python
raw_path: bytes
```

### query\_string`instance-attribute`

```python
query_string: bytes
```

### root\_path`instance-attribute`

```python
root_path: NotRequired[str]
```

### headers`instance-attribute`

```python
headers: ScopeHeaders
```

### client`instance-attribute`

```python
client: NotRequired[tuple[str, int]]
```

### server`instance-attribute`

```python
server: tuple[str, int | None]
```

### subprotocols`instance-attribute`

```python
subprotocols: list[str]
```

### state`instance-attribute`

```python
state: NotRequired[State]
```

### extensions`instance-attribute`

```python
extensions: WebSocketExtensions
```

## WebSocketConnect

Bases: `TypedDict`

A WebSocket connect event in [`ReceiveMessage`](https://h2corn.monicz.dev/api/applications/#h2corn.ReceiveMessage "ReceiveMessage module-attribute").

### type`instance-attribute`

```python
type: Literal['websocket.connect']
```

## WebSocketReceiveBytes

Bases: `TypedDict`

A binary WebSocket event in [`ReceiveMessage`](https://h2corn.monicz.dev/api/applications/#h2corn.ReceiveMessage "ReceiveMessage module-attribute").

### type`instance-attribute`

```python
type: Literal['websocket.receive']
```

### bytes`instance-attribute`

```python
bytes: bytes
```

### text`instance-attribute`

```python
text: NotRequired[None]
```

## WebSocketReceiveText

Bases: `TypedDict`

A text WebSocket event in [`ReceiveMessage`](https://h2corn.monicz.dev/api/applications/#h2corn.ReceiveMessage "ReceiveMessage module-attribute").

### type`instance-attribute`

```python
type: Literal['websocket.receive']
```

### text`instance-attribute`

```python
text: str
```

### bytes`instance-attribute`

```python
bytes: NotRequired[None]
```

## WebSocketDisconnect

Bases: `TypedDict`

A WebSocket disconnect event in [`ReceiveMessage`](https://h2corn.monicz.dev/api/applications/#h2corn.ReceiveMessage "ReceiveMessage module-attribute").

### type`instance-attribute`

```python
type: Literal['websocket.disconnect']
```

### code`instance-attribute`

```python
code: int
```

### reason`instance-attribute`

```python
reason: NotRequired[str]
```

## WebSocketAccept

Bases: `TypedDict`

A WebSocket accept event in [`SendMessage`](https://h2corn.monicz.dev/api/applications/#h2corn.SendMessage "SendMessage module-attribute").

### type`instance-attribute`

```python
type: Literal['websocket.accept']
```

### subprotocol`instance-attribute`

```python
subprotocol: NotRequired[str | None]
```

### headers`instance-attribute`

```python
headers: NotRequired[Headers]
```

## WebSocketSendBytes

Bases: `TypedDict`

A binary WebSocket event in [`SendMessage`](https://h2corn.monicz.dev/api/applications/#h2corn.SendMessage "SendMessage module-attribute").

### type`instance-attribute`

```python
type: Literal['websocket.send']
```

### bytes`instance-attribute`

```python
bytes: bytes
```

### text`instance-attribute`

```python
text: NotRequired[None]
```

## WebSocketSendText

Bases: `TypedDict`

A text WebSocket event in [`SendMessage`](https://h2corn.monicz.dev/api/applications/#h2corn.SendMessage "SendMessage module-attribute").

### type`instance-attribute`

```python
type: Literal['websocket.send']
```

### text`instance-attribute`

```python
text: str
```

### bytes`instance-attribute`

```python
bytes: NotRequired[None]
```

## WebSocketClose

Bases: `TypedDict`

A WebSocket close event in [`SendMessage`](https://h2corn.monicz.dev/api/applications/#h2corn.SendMessage "SendMessage module-attribute").

### type`instance-attribute`

```python
type: Literal['websocket.close']
```

### code`instance-attribute`

```python
code: NotRequired[int]
```

### reason`instance-attribute`

```python
reason: NotRequired[str | None]
```

## WebSocketHTTPResponseStart

Bases: `TypedDict`

A WebSocket HTTP response-start event in [`SendMessage`](https://h2corn.monicz.dev/api/applications/#h2corn.SendMessage "SendMessage module-attribute").

### type`instance-attribute`

```python
type: Literal['websocket.http.response.start']
```

### status`instance-attribute`

```python
status: int
```

### headers`instance-attribute`

```python
headers: NotRequired[Headers]
```

## WebSocketHTTPResponseBody

Bases: `TypedDict`

A WebSocket HTTP response-body event in [`SendMessage`](https://h2corn.monicz.dev/api/applications/#h2corn.SendMessage "SendMessage module-attribute").

### type`instance-attribute`

```python
type: Literal['websocket.http.response.body']
```

### body`instance-attribute`

```python
body: NotRequired[bytes]
```

### more\_body`instance-attribute`

```python
more_body: NotRequired[bool]
```
