The following example demonstrates a basic WebSocket test script. Adjust the samplers to match your use case.
Sampler reference
| Sampler | Purpose | Blocking behavior |
|---|
| WebSocket Open Connection | Opens a WebSocket connection to the server | Blocks until connection is established or times out |
| WebSocket Ping/Pong | Sends a ping frame and waits for a pong frame | Blocks until pong is received or times out |
| WebSocket request-response Sampler | Sends a frame and reads one response | Blocks until a response is read or times out |
| WebSocket Single Write Sampler | Sends a frame without waiting for a response | Non-blocking |
| WebSocket Single Read Sampler | Reads one response from the queue | Blocks until a response is read or times out |
| WebSocket Close | Closes the connection through negotiation | Blocks until close handshake completes |
For proxy services, data filtering, and data sharding samplers, see the JMeter WebSocket Samplers documentation.
Build the script
Right-click Test Plan and choose Add > Threads (Users) > Thread Group.
Add the following samplers to the thread group in order. Right-click Thread Group and choose Add > Sampler > *sampler name* for each one.
a. WebSocket Open Connection
Configure the Server URL section to point to the service under test.

Note This example targets a Python Echo service that echoes every received message. The sample server code:
Example server.py code
import asyncio
import websockets
async def echo(websocket, path):
async for message in websocket:
message = "Your message: {}".format(message)
await websocket.send(message)
asyncio.get_event_loop().run_until_complete(websockets.serve(echo, '0.0.0.0', 8080))
asyncio.get_event_loop().run_forever()
b. WebSocket Ping/Pong
Set Pong (read) timeout (ms) to 6000. If JMeter does not receive a pong frame within 6,000 ms, the sampler fails and reuses the existing connection.

c. WebSocket request-response Sampler
This sampler sends a frame and reads the response in a single step.
| Parameter | Example value | Description |
|---|
| Connection | use existing connection | Reuses the connection opened earlier. |
| Data type | Text | Frame data type. |
| Request data | PTS | The payload to send. |
| Response (read) timeout (ms) | 6000 | Maximum wait time for a response. |

d. WebSocket Single Write Sampler
This sampler sends a frame and returns immediately without waiting for a response.
| Parameter | Example value | Description |
|---|
| Connection | use existing connection | Reuses the connection opened earlier. |
| Data type | Text | Frame data type. |
| Request data | PTS bang bang bang | The payload to send. |

e. WebSocket Single Read Sampler
This sampler reads the next response from the queue without sending anything.
| Parameter | Example value | Description |
|---|
| Connection | use existing connection | Reuses the connection opened earlier. |
| Data type | Text | Frame data type. |
| Response (read) timeout (ms) | 6000 | Maximum wait time for a response. |

f. WebSocket Close
Closes the WebSocket connection through the standard close handshake. A successful close returns 1000:sampler requested close.
| Parameter | Example value | Description |
|---|
| Close status | 1000 | Status code sent in the close frame (first two bytes of the data frame). |
| Response (read) timeout (ms) | 6000 | Maximum wait time for the close acknowledgment. |

(Optional) Add HTTP headers
To include headers such as authentication tokens, right-click Thread Group and choose Add > Config Element > HTTP Header Manager. For details, see the Apache JMeter Header Manager documentation.
Add a listener
Right-click Thread Group and choose Add > Listener > View Results Tree to inspect request and response data during debugging.