tencent cloud

All product documents
Tencent Cloud Observability Platform
Conn Overview
Last updated: 2025-03-11 20:05:06
Conn Overview
Last updated: 2025-03-11 20:05:06
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
send()
number
Send request data.
recv()
ArrayBuffer
Receive response data.
close()
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);
}

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon