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

# WebSocketClient

`std/websocket-client@1`. Opens a peer Session. Each complete message is one value; each graph write is journaled before I/O. One terminal ends the Session, not a message.

## Declaration

This declaration comes from `crates/rastok/src/lab.rs`. Place the Connector in a Graph
and wire its ports; the excerpt alone is not an App.

```rkg
connector network : WebSocketClient {
  url = "wss://example.test/socket"
  handshake_timeout = duration("5s")
  codec = json
   behavior = deterministic
}
```

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 | `auth_bearer` | `string` | optional | instance |
| all | `behavior` | `deterministic \| probabilistic` | required | plan |
| all | `codec` | `bytes \| json \| string` | required | plan |
| all | `handshake_timeout` | `duration` | required | instance |
| all | `headers` | `HTTP headers` | optional | instance |
| all | `custom_headers` | `map<string,array<string>>` | optional | instance |
| all | `max_message` | `ByteSize` | `"8MiB"` | plan |
| all | `subprotocols` | `array<string>` | optional | instance |
| all | `tls_ca` | `array<byte>` | optional | instance |
| all | `tls_certificate` | `array<byte>` | optional | instance |
| all | `tls_private_key` | `array<byte>` | optional | instance |
| all | `url` | `string` | required | 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, writes and terminal outcomes separately.
Input after a terminal may open a successor Session; old writes are not resent
automatically.

## Qualification inventory

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