---
sidebar_position: 8
title: WebSocket
description: Open a WebSocket session and send a message through a session-backed follow-up step.
---
Source file:
[examples/ws_protocol.hen](https://gitlab.com/ben_goodman/apps/hen/-/blob/main/examples/ws_protocol.hen)
## What It Demonstrates
- `protocol = ws`
- a session-opening request
- a later session-backed send step
- capturing the reply body from the message exchange flow
## Key Pattern
```hen
protocol = ws
session = chat
GET {{ WS_ORIGIN }}/ws
---
session = chat
within = 1s
~~~
<Root seed="0">
<Document>
<Text>
1. Sentence:
<Sentence min="3" max="10"/>
</Text>
</Document>
</Root>
~~~
```
## Run It
```bash
hen verify ./examples/ws_protocol.hen
hen run ./examples/ws_protocol.hen all --non-interactive
```
## What To Notice
- The session-opening step establishes the WebSocket connection.
- The later body-backed step reuses that session.
- In the current example, the received body is captured for callback output rather than asserted.
Related reference: [Protocols](../reference/protocols.md)