Send a data string through the connection. You can use JSON.stringify to convert a JSON or JavaScript values to a JSON string.
Parameter | Type | Description |
---|---|---|
data | string / ArrayBuffer | The data to send. |
Example
A k6 script that demonstrates how to add an event listener for the open WebSocket connection event sends a message and closes the connection.
example-websocket-send.js
The preceding example uses a WebSocket echo server, which you can run with the following command: