Socket
Note
A module with a better and standard API exists.
The new k6/experimental/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.
Socket
is a WebSocket client to interact with a WebSocket connection. You can use it to listen various events happening on the WebSocket connection and send messages to the server. Additionally, you can use socket.setTimeout() and socket.setInterval() to execute code in the background, or repeatedly, while the WebSocket connection is open.
WebSocket built-in metrics
k6
automatically collects metrics when interacting with a WebSocket service through the k6/ws
API.
Review the list in the metrics reference.
Check out the Results output article for more information about how to process the metric information.