Skip to content

This was a training project to learn about writing complex k6 extensions.

Notifications You must be signed in to change notification settings

saniyar-dev/xk6-tcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xk6-tcp

This extension adds the ability to open and write on TCP sockets in the term of new HTTP Design.

See this link for more details.

Requirements

Getting started

  1. Build the k6 binary: make build

  2. Run an example: ./k6 run ./examples/test.js

Usage/Examples

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

export default async function () {
  const socket = await TCP.open('192.168.1.1:80', {
                            // default      | possible values
    ipVersion: 0,           // 0            | 4 (IPv4), 6 (IPv6), 0 (both)
    keepAlive: true,        // false        |
    lookup: null,           // dns.lookup() |
    proxy: 'myproxy:3030',  // ''           |
  });
  console.log(socket.active); // true

  // Writing directly to the socket.
  // Requires TextEncoder implementation, otherwise typed arrays can be used as well.
  await socket.write(new TextEncoder().encode('GET / HTTP/1.1\r\n\r\n'));

  // And reading...
  socket.on('data', data => {
    console.log(`received ${data}`);
    socket.close();
  });

  await socket.done();
}

🔗 Links

linkedin twitter

About

This was a training project to learn about writing complex k6 extensions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages