> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bringits.com/llms.txt
> Use this file to discover all available pages before exploring further.

# WebSocket Close

> Signal the active WebSocket connection to perform a clean close

The WebSocket Close command (Command Type: 9) signals the active WebSocket connection to perform a clean close. Place at the end of an `onMessage` chain to terminate the connection once the desired condition is met.

## Command Type

**Command Type ID:** 9

## Parameters

No parameters. This command takes no configuration.

## Behavior and Edge Cases

* It signals the connection to close cleanly; any frames already buffered are processed before the socket actually closes (the `onClose` hook then runs).
* Calling it when there is **no active connection is a safe no-op** — it does nothing and raises no error. This means it is safe to place at the end of an `onConnect` or `onMessage` chain even if the socket has already closed.
* After a close, the step publishes its current accumulated result once; a mid-flow (non-last) step uses this to capture a one-time snapshot and move on.

## Usage Examples

### Close After Receiving Target Data

Used at the end of an `onMessage` chain to stop the connection once desired data has been collected:

```json theme={null}
{
  "command": "websocket",
  "params": {
    "url": "wss://stream.example.com",
    "onMessage": [
      { "id": 6, "type": "PARSE", "params": { "path": "$.events" } },
      { "id": 9, "type": "WS", "params": {} }
    ]
  }
}
```

## Common Use Cases

* **Single-Response Collection**: Connect, receive one meaningful message, then close
* **Conditional Termination**: Combined with If-Else, close only when a stopping condition is met

## Related Commands

* [WebSocket](/stream/commands/ws/websocket) - The parent command
* [If-Else](/stream/commands/execution-flow/if-else) - Conditionally trigger a close
