No results for

Powered byAlgolia
⚠️ This is archived documentation for v0.43. Go to the latest version

An extension with much better and standard API exists

xk6-websockets implements the WebSockets API living standard. While the implementation isn't full, it uses a global event loop instead of local one.

Currently, it's available as an experimental module k6/experimental/websockets. It is also likely that it will at some point become part of the core of k6.

The ws module provides a WebSocket client implementing the WebSocket protocol.

connect( url, params, callback )Create a WebSocket connection, and provides a Socket client to interact with the service. The method blocks the test finalization until the connection is closed.
ParamsUsed for setting various WebSocket connection parameters such as headers, cookie jar, compression, etc.
SocketWebSocket client used to interact with a WS connection.
Socket.close()Close the WebSocket connection.
Socket.on(event, callback)Set up an event listener on the connection for any of the following events:
- open
- binaryMessage
- message
- ping
- pong
- close
- error. a ping.
Socket.send(data)Send string data.
Socket.sendBinary(data)Send binary data.
Socket.setInterval(callback, interval)Call a function repeatedly at certain intervals, while the connection is open.
Socket.setTimeout(callback, period)Call a function with a delay, if the connection is open.