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

# Load Testing WebSockets

> Guide on load testing WebSocket-based applications with LoadForge using Locust.

## Overview

LoadForge provides support for generic WebSocket testing via the `WebSocketUser` from `locust-plugins`. You can open WebSocket connections, send and receive messages, and simulate concurrency to measure performance under load.

## Locust Test Script (locust.py)

```python theme={null}
# locust.py
import time
from locust import HttpUser, between, task
from locust_plugins.users import WebSocketUser

class MyWebSocketUser(WebSocketUser):
    wait_time = between(1, 3)
    host = "wss://YOUR_WS_URL_HERE"

    def on_start(self):
        # Connect to WebSocket server
        self.connect("/ws")

    @task
    def send_message(self):
        # Send a message to the WebSocket
        self.send("hello", name="SendMessage")
        # Optionally wait for server response
        time.sleep(1)

    def on_message(self, message):
        # Handle incoming message
        print(f"Received: {message}")

```

***

**Notes:**

* Install dependencies: `pip install locust locust-plugins websockets` if you wish to test locally.
* Replace `YOUR_WS_URL_HERE` and endpoint `/ws` with your actual WebSocket URL and path.
