Skip to content

Function: tcpPing() ​

tcpPing(host, port, options?): Effect<DiagnosticStep>

Defined in: diagnostics.ts:141

Tests TCP connectivity to a host and port.

Attempts to establish a TCP connection and measures the time taken. This is useful for checking if a port is open and reachable.

Parameters ​

host ​

Host

A validated Host type (Hostname or IpAddress)

port ​

Port

A validated Port branded type (1-65535)

options? ​

TcpPingOptions = {}

Optional configuration including name and timeoutMs (as TimeoutMs)

Returns ​

Effect<DiagnosticStep>

An Effect that resolves to a DiagnosticStep with connection status

Example ​

typescript
import { Hostname, Port, TimeoutMs } from '@univ-lehavre/atlas-net';

// Check if a web server is reachable
const step = await Effect.runPromise(tcpPing(Hostname('example.com'), Port(443)));
console.log(`Connection ${step.status} in ${step.latencyMs}ms`);

// With custom timeout
const step2 = await Effect.runPromise(
  tcpPing(Hostname('slow-server.com'), Port(8080), { timeoutMs: TimeoutMs(10000) })
);