xk6-tcp
    Preparing search index...

    xk6-tcp

    TCP Protocol Extension for k6

    This extension provides TCP socket functionality for k6 performance testing scripts, offering both synchronous and asynchronous APIs for network communication.

    Supports event-driven programming with lifecycle events (connect, data, close, error, timeout), TLS/SSL encryption, binary data handling, and comprehensive metrics collection.

    import { Socket } from 'k6/x/tcp';

    export default function () {
    const socket = new Socket();

    socket.on('connect', () => {
    console.log('Connected!');
    socket.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n');
    });

    socket.on('data', (data) => {
    const response = String.fromCharCode.apply(null, new Uint8Array(data));
    console.log('Received:', response.substring(0, 100));
    socket.destroy();
    });

    socket.on('close', () => {
    console.log('Connection closed');
    });

    socket.connect(80, 'example.com');
    }

    Classes

    Socket

    Interfaces

    ConnectOptions
    SocketOptions
    WriteOptions

    Type Aliases

    SocketEvent
    SocketState