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

Conn Overview

PDF
Focus Mode
Font Size
Last updated: 2025-03-10 17:28:37
By using the new socket.Conn method, you can create a Socket instance. The parameters of this method include the protocol name (tcp or udp), service address, and service port.

Constructor

new Conn(): Conn

Parameters

Parameter
Type
Description
network
string
The protocol name used to establish the connection (tcp or udp).
host
string
The IP address of the service.
port
number
The port of the service.

Methodology

Methodology
Return Type
Description
number
Send request data.
ArrayBuffer
Receive response data.
void
Close the connection.

Samples

Establish a socket connection to initiate a tcp/udp request.
import socket from "pts/socket";
import util from 'pts/util';
import {sleep} from 'pts';

export default function () {
const tcp_socket = new socket.Conn('tcp', '127.0.0.1', 80);
const send_data = `GET /get HTTP/1.1
Host: 127.0.0.1
User-Agent: pts-engine
\\r\\n`;
tcp_socket.send(util.toArrayBuffer(send_data));
const bytes_read = tcp_socket.recv(512);
tcp_socket.close();
console.log(bytes_read);
sleep(1);
}


Help and Support

Was this page helpful?

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

Feedback