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:34
The pts/socketio module in the JavaScript API implements socketio-related features.

Methodology

Methodology
Return Type
Description
Establish a Socket.IO connection and define the business logic in the callback function. After the callback function has been executed, a Response object will be returned.

Object

Object
Description
Optional configuration items when establishing a connection using the connect method.
If the connection is successfully established, the created Socket.IO object will be passed into the callback function. You can define your request logic and send/receive event messages in this callback function.
After the callback function has been executed, the connect method will return a Response object.

Samples

// SocketIO API
import socketio from 'pts/socketio';
import { check } from 'pts';
import util from 'pts/util';

export default function () {
const res = socketio.connect('http://localhost:8080', function (socket) {
socket.on('open', () => console.log('connected'));
socket.on('message', (data) => console.log('message received: ', data));
socket.on('binaryMessage', (data) => console.log('binaryMessage received: ', data));
socket.on('close', () => console.log('disconnected'));
socket.setTimeout(function () {
console.log('3 seconds passed, closing the socket');
socket.close();
}, 3000);
// Set the scheduled task.
socket.setTimeout(function () {
socket.emit('message', 'hello');
socket.emit('binaryMessage', util.base64Decoding('aGVsbG8=', 'std', 'b'));
socket.emit('ackMessage', 'hello ack', function(msg) {
console.log('ack message received: ', msg)
})
}, 500);
// Set the periodic task.
socket.setInterval(function(){
socket.emit('message', 'interval message');
}, 500);
}, {
// Support polling and WebSocket protocols.
protocol:'websocket',
headers: {
token: 'ZER3XSR',
}
});
check('status is 200', () => res.status === 200);
}


Help and Support

Was this page helpful?

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

Feedback