Documentation Index
Fetch the curated documentation index at: https://grafana_com_website/llms.txt
Fetch the complete documentation index at: https://grafana_com_website/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: /docs/k6/latest/javascript-api/k6-ws/socket/socket-sendbinary.md (append .md) or send Accept: text/markdown to /docs/k6/latest/javascript-api/k6-ws/socket/socket-sendbinary/. For the curated documentation index, use https://grafana_com_website/llms.txt. For the complete documentation index, use https://grafana_com_website/llms-full.txt.
Socket.sendBinary(data)
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.
Send binary data through the connection.
| Parameter | Type | Description |
|---|---|---|
| data | ArrayBuffer | The data to send. |
Example
import ws from 'k6/ws';
const binFile = open('./file.pdf', 'b');
export default function () {
ws.connect('http://wshost/', function (socket) {
socket.on('open', function () {
socket.sendBinary(binFile);
});
socket.on('binaryMessage', function (msg) {
// msg is an ArrayBuffer, so we can wrap it in a typed array directly.
new Uint8Array(msg);
});
});
}- See also Socket.send(data)
Was this page helpful?
Related resources from Grafana Labs

