Skip to content

Latest commit

 

History

History
30 lines (23 loc) · 714 Bytes

File metadata and controls

30 lines (23 loc) · 714 Bytes
title excerpt
Socket.ping()
Send a ping. Ping messages can be used to verify that the remote endpoint is responsive.

Send a ping. Ping messages can be used to verify that the remote endpoint is responsive.

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.on('pong', function () {
        // As required by the spec, when the ping is received, the recipient must send back a pong.
        console.log('connection is alive');
      });

      socket.ping();
    });
  });
}