Using the net module
When your transaction test script needs to establish a TCP connection with a network target, you'll use the net
module from ThousandEyes. The ThousandEyes runtime environment for transaction scripts includes the net
module for creating raw TCP client sockets to servers on arbitrary ports.
Importing the Module
To use the net
module, make sure to first import it within your transaction script:
import net from 'thousandeyes';
Creating a Connection
To create a client connection to a remote server, use the net.connect
function:
await net.connect(<port>, '<host.ip.address>');
Sending Data
To send data over the socket connection, first assign the result of net.connect
to a variable:
let socket = await net.connect(80, '1.1.1.1');
Then, use the write
or writeAll
methods to send data over the socket:
await socket.writeAll('GET / HTTP/1.1\r\n\r\n');
To read from the socket, use the read
or readAll
methods:
const response = await socket.readAll();
Example GET Request
In the following example, notice that first the net
module is imported. Then, after net.connect
is called, data is sent and received over the socket, using write
and read
:
Advanced Examples
For additional examples, see the public repository of ThousandEyes transaction scripts.
Example: IMAP Login
In the following example, you establish a TCP connection; then send IMAP credentials over the connection you've created:
Last updated