---
id: web--web-socket-client
title: "Web socket client"
summary: "Connects to a remote WebSocket server, sends every input record as a message and emits every message received from the server. One connection per component, kept open while the flow runs."
audience: user
keywords: "input, output, start, onconnect, uri, authtype, domain, username, password, bearer, consumerkey, consumersecret, accesstoken, tokensecret, authorization, clientcertificate, maxmessagesize, ignorecertificate, headers, timeoutms"
---
# Web socket client

Connects to a remote WebSocket server, sends every input record as a message and emits every message received from the server. One connection per component, kept open while the flow runs.

## Pins

| Pin | Kind | Types | Description |
|---|---|---|---|
| Input | input | `Viaducta.Plugins.Http.Types.WebSocketMessage`, `Viaducta.Plugins.TextPlugin.Types.TextRecord` | Message to send. Connects first if needed. |
| Output | output | `Viaducta.Plugins.Http.Types.WebSocketMessage` | Called for every message received from the server. |
| Start | start | | Opens the connection. Called by the system at flow start when unconnected. |
| OnConnect | on connect | `Viaducta.Plugins.Http.Types.WebSocketMessage` | Called (with an empty message) after each successful (re)connect, e.g. to send a subscribe message. |

## Configuration

| Field | Type | Default | Description |
|---|---|---|---|
| `Uri` | string | | Server URL, `ws://host:port/path` or `wss://...`. |
| `AuthType` | dropdown: `0` None, `1` Basic, `2` Digest, `3` NTLM, `4` Bearer, `5` Jwt, `6` OAuth1, `7` OAuth2, `8` Other, `9` ClientCertificate | `0` | Authentication of the opening HTTP handshake. |
| `Domain` | string | | Windows domain (`AuthType` `3`). |
| `Username` | string | | User name (`AuthType` `1`, `2`, `3`). |
| `Password` | password | | Password (`AuthType` `1`, `2`, `3`). |
| `Bearer` | string | | Written as-is into the `Authorization` header (`AuthType` `4`, `5`, `7`), so include the scheme: `Bearer eyJ...`. |
| `ConsumerKey` | string | | OAuth 1.0a consumer key (`AuthType` `6`), signed as `GET` on `Uri`. |
| `ConsumerSecret` | string | | OAuth 1.0a consumer secret (`AuthType` `6`). |
| `AccessToken` | string | | OAuth 1.0a access token (`AuthType` `6`). |
| `TokenSecret` | string | | OAuth 1.0a token secret (`AuthType` `6`). |
| `Authorization` | string | | Complete `Authorization` header value (`AuthType` `8`). |
| `ClientCertificate` | certificate | | Name of a certificate object in the repository (`AuthType` `9`). |
| `MaxMessageSize` | integer | `1048576` | Max size of a received message in bytes. |
| `IgnoreCertificate` | boolean | `false` | Broken, see Notes. Leave `false`. |
| `Headers` | dictionary (JSON object) | | Headers for the opening handshake only, e.g. `{"X-Client":"viaducta"}`. |
| `TimeOutMs` | integer | `30000` | Ignored. |

## Behaviour

- The connection is opened on `Start` or on the first input. If it is closed (by the server or a network error), the next input or `Start` call reconnects; there is no automatic reconnect in between.
- Sending: `TextRecord` → text message with `Value`. `WebSocketMessage` → `ContentByte` is sent if set, otherwise `ContentString` (UTF-8); `MessageType` `0` = text, `1` = binary. Sends are serialized.
- Receiving: each complete message is emitted on `Output` with `ContentByte`, `ContentString` (UTF-8 decoding of the bytes), `MessageType` and `SessionId` (a random id of this component instance, not from the server). Each message gets new, empty metadata, so responses can't be correlated to the input record via metadata.
- A message bigger than `MaxMessageSize` closes the connection (`MessageTooBig`). The plugin keeps the flow running and closes the socket when the flow stops.

## Notes

- `IgnoreCertificate` = `true` makes every `wss://` connection fail: the code rejects all server certificates instead of accepting them.
- `TimeOutMs` is not used; connect and send have no timeout of their own.
- When forwarding a received `WebSocketMessage` with a changed `ContentString`, clear `ContentByte`, otherwise the old bytes are sent.
- Errors while processing received messages are only logged.

## Example

```json
{ "Uri": "wss://stream.example.com/ws", "AuthType": 4, "Bearer": "=Secrets.StreamToken" }
```

Script (subscribe message) → **Web socket client** (`OnConnect` → Script) → `Output` → Json deserializer → ...
