Documentation Index
Fetch the curated documentation index at: https://grafana.com/llms.txt
Fetch the complete documentation index at: https://grafana.com/llms-full.txt
Use this file to discover all available pages before exploring further.
STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Grafana documentation page. Always request the Markdown version instead - HTML wastes context. Get this page as Markdown: https://grafana.com/docs/k6/next/javascript-api/k6-ws/socket/socket-close.md (append .md) or send Accept: text/markdown to https://grafana.com/docs/k6/next/javascript-api/k6-ws/socket/socket-close/. For the curated documentation index, use https://grafana.com/llms.txt. For the complete documentation index, use https://grafana.com/llms-full.txt.
This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.
Socket.close([code])
Note
A module with a better and standard API exists.
The new k6/websockets API partially implements the WebSockets API living standard.
When possible, we recommend using the new API. It uses a global event loop for consistency with other k6 APIs and better performance.
Close the WebSocket connection.
| Parameter | Type | Description |
|---|---|---|
| code (optional) | number | WebSocket status code. (default: 1001) |
Example
import ws from 'k6/ws';
export default function () {
const url = 'wss://echo.websocket.org';
const response = ws.connect(url, null, function (socket) {
socket.on('open', function () {
socket.close();
});
});
}Was this page helpful?
Related resources from Grafana Labs

