Release Notes
export default function() { ... }) until the performance testing ends.ws.connect method that establishes the connection, until the connection is closed. However, in the callback function (function (socket) {...}) after the connection is established, the corresponding method will continuously listen on and process asynchronous events until the performance testing ends.ws.connect method to establish a connection and define your business logic in its callback function:ws.connect include the URL and callback function.ws.Socket object to the callback function. You can define your WebSocket request logic in the callback function.ws.connect method will return a ws.Response object.ws.Socket object:send: sends a text message.close: closes a connection.on: listens on events and processes them with the callback function. PTS supports the following events.Event name | Event Purpose |
open | Establishes a connection. |
close | Closes a connection. |
error | Reports an error. |
message | Receives a text message. |
binaryMessage | Receives a binary message. |
pong | Receives a pong message. |
ping | Receives a ping message. |
import ws from 'pts/ws';import { check, sleep } from 'pts';export default function () {const res = ws.connect("ws://localhost:8080/echo", function (socket) {socket.on('open', () => console.log('connected'));socket.on('message', (data) => console.log('Message received: ', data));socket.on('close', () => console.log('disconnected'));socket.send("message");socket.setTimeout(function () {console.log('3 seconds passed, closing the socket');socket.close();}, 3000);socket.setInterval(function () {socket.ping();}, 500);socket.setLoop(function () {sleep(0.1)socket.send("loop message")});});check("status is 101", () => res.status === 101);}
Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback