tencent cloud

Performance Testing Service

Overview
Purchase Guide
Billing Overview
Pay-as-You-Go (postpaid)
Purchasing Channels
Payment Overdue
Refund Instructions
Quick Start
Operation Guide
Performance Testing in Simple Mode
Performance Testing in Script Mode
Performance Testing in JMeter Mode
Project Management
Scenario Management
Traffic Recording
Environment Management
Scheduled Performance Testing
Performance Testing Report
Access Control
Alarm Management
Tag Management
Error Code Manual
Practice Tutorial
Using Prometheus To Monitor Performance Testing Metrics
Using PTS to Playback Requests Recorded by GoReplay
API Documentation
History
Introduction
API Category
Making API Requests
PTS-related APIs
Data Types
Error Codes
JavaScript API List
Overview of JavaScript API List
pts/global
pts/http
pts
pts/dataset
pts/grpc
pts/jsonpath
pts/protobuf
pts/redis
pts/sql
pts/url
pts/util
pts/ws
pts/socketio
pts/socket
FAQs
Related Agreements
Service Level Agreement
Use Limits
Privacy Policy
Data Processing And Security Agreement

Module Overview

PDF
Focus Mode
Font Size
Last updated: 2025-03-10 17:28:32
The pts/ws module in the JavaScript API is used to implement basic features based on the Websocket protocol.

Methodology

Methodology
Return Type
Description
Establish a WebSocket connection and define the business logic in the callback function. After the callback function has been executed, ws.connect returns a ws.Response object.

Object

Object
Description
After successfully establishing the connection with ws.connect, pass the ws.Socket object into the callback function to define the WebSocket request logic.
The ws.Response object returned by ws.connect after executing the callback function.

Samples

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.on('ping', () => console.log('ping'));
socket.on('pong', () => console.log('pong'));
socket.on('error', (e) => console.log('error happened', e.error()));
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);
};


Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback