Miha Jakovac

Logo

.NET & DevOps Engineer | Cloud Specialist | Team Enabler

My name is Miha and I've been tinkering with computers for some time now. I remember getting Pentium 100 in the late '90s and that's how it all started.

Specialities:

13 January 2021

Send a TCP probe test with QAToolKit

by Miha J.

Lately, I’ve been working on tests that needed to connect to the service through the TCP protocol. The service was accepting a command and returning a response with results.

To achieve that, you can use the QAToolKit Probes library to create a TCP Probe, which is an excellent addition to the HTTP and ICMP tests we looked at earlier.

The code below shows how easy it is to create a new TCP probe and send a message. You can also send a list of statements depending on your needs. The probe processes them in sequence and returns a response message.

//Copy and paste code
using QAToolKit.Engine.Probes.Probes;
using System;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    class Program
    {
        private static async Task Main(string[] args)
        {           
                var tcpProbe = new TcpProbe("tcpbin.com", 4242, new[] { "HELLO\n" });
                var result = await tcpProbe.Execute();
                Console.WriteLine($"tcpbin.com:4242 responded with {result.ResponseData}");
        }
    }
}

And here is the output:

tcpbin.com:4242 responded with HELLO

As always, you can also use QAToolKit to write xUnit or NUnit tests. Simple & useful. :)

tags: c# - tool - qatoolkit - tcp