Skip to content

Latest commit

 

History

History
33 lines (25 loc) · 801 Bytes

File metadata and controls

33 lines (25 loc) · 801 Bytes
title excerpt
Socket.send(data)
Send a data string through the connection.

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 The data to send.

Example

import ws from 'k6/ws';

export default function () {
  const url = 'ws://echo.websocket.org';
  const response = ws.connect(url, null, function (socket) {
    socket.on('open', function () {
      socket.send('my-message');
      socket.send(JSON.stringify({ data: 'hola' }));
    });
  });
}