---
title: WebSocketServer
description: Ports, terminal outcomes, settings and qualification evidence for
  the WebSocketServer connector.
url: https://docs.rastok.com/reference/connectors/websocket-server
source_revision: v0.2.0-alpha
---

# WebSocketServer

`std/websocket-server@1`. Accepts peer Sessions. Replies follow session lineage or an explicit `correlate`. A pre-admission handshake refusal creates no Session or exit.

## Declaration

This declaration comes from `examples/agent-gateway.rkg`. Place the Connector in a Graph
and wire its ports; the excerpt alone is not an App.

```rkg
connector clients : WebSocketServer {
  listen = "127.0.0.1:8443"
  path = "/agent"
  codec = json
  handshake_timeout = duration("5s")
  max_message = "1MiB"
  correlate = meta.ext.session_id
  versions = ["http/1.1"]
}
```

The [contract index](/reference/contracts.md) explains shared settings, build features
and the distinction between a Contract, a Lab model and an installed Driver.

See [instance ownership and bounded admission](/reference/execution.md#instances-own-state-not-threads); this Contract uses Sessions, not the outbound Call queue rule.

| Mode | Driver direction | Exchange | Lab model | Installed in this binary |
|---|---|---|---|---|
| No selector | inbound+outbound | session | `lab-websocket` | Not compiled |

## Ports and completion

| Mode | Port | Direction | Type rule |
|---|---|---|---|
| all | `in` | input | `codec = bytes` → `array<byte>`; `codec = json` → `variant`; `codec = string` → `string` |
| all | `out` | output | Same as `in` |
| all | `exit` | output | WebSocketExit, below |

| Mode | Output cardinality |
|---|---|
| all | Zero or more frames and writes; exactly one `exit` per Session |

## Exit union

| Case | Payload | Call visibility |
|---|---|---|
| `Closed` | `{ code: int, reason: string }` | Not an outbound Call |
| `ConnectFailed` | Empty | Not an outbound Call |
| `DecodeFailed` | Empty | Not an outbound Call |
| `DnsFailed` | Empty | Not an outbound Call |
| `HandshakeRejected` | `{ status: int }` | Not an outbound Call |
| `MessageTooLarge` | `{ limit: ulong }` | Not an outbound Call |
| `OutcomeUnknown` | Empty | Not an outbound Call |
| `ProtocolFailed` | Empty | Not an outbound Call |
| `TimeoutExpired` | Empty | Not an outbound Call |
| `TlsFailed` | Empty | Not an outbound Call |
| `TransportLost` | Empty | Not an outbound Call |

## Settings

With `codec = json`, `rastok check` refuses a producer whose resolved type
contains a [value without a JSON form](/reference/types.md#json-request-values), using
`E-TYPE-INVALID`. A `variant` producer is checked at execution instead: an
unencodable message ends the Session with `DecodeFailed` before it is sent.

| Mode | Setting | Domain | Presence / default | Latest phase |
|---|---|---|---|---|
| all | `allowed_origins` | `array<string>` | optional | instance |
| all | `auth_bearer` | `string` | optional | instance |
| all | `behavior` | `deterministic` | `deterministic` | plan |
| all | `codec` | `bytes \| json \| string` | required | plan |
| all | `correlate` | `string` | optional | invocation |
| all | `handshake_timeout` | `duration` | required | instance |
| all | `headers` | `HTTP headers` | optional | instance |
| all | `custom_headers` | `map<string,array<string>>` | optional | instance |
| all | `listen` | `string` | required | instance |
| all | `max_message` | `ByteSize` | `"8MiB"` | plan |
| all | `path` | `string` | `"/"` | plan |
| all | `subprotocols` | `array<string>` | optional | instance |
| all | `tls_certificate` | `array<byte>` | optional | instance |
| all | `tls_private_key` | `array<byte>` | optional | instance |
| all | `versions` | `array<http/1.1 \| http/2 \| http/3>` | `["http/3", "http/2", "http/1.1"]` | plan |
| all | `zero_rtt` | `disabled` | `disabled` | plan |

The Lab has an effectless Session binding, but authored WebSocket Session
mocks are not executable. `rastok check` refuses a `mock` on this Connector
with `E-CHECK-DEFERRED`; a declaration without a mock still checks. Driver
tests cover Session opening, frames and terminal outcomes separately from a
physical listener, authentication or wire handshake. Explicit correlation
never chooses another Connector's Session.

## Qualification inventory

No dedicated full-Contract fixture is declared. Related tests: `crates/rastok/src/connector/drivers/network/websocket.rs`.
