Function: performSinglePortCheck()
performSinglePortCheck(
host
:string
,port
:number
,timeout
:number
):Promise
<MonitorCheckResult
>
Defined in: electron/services/monitoring/utils/portChecker.ts:88
Performs a single TCP port connectivity check to a specified host and port, without retry logic.
Parameters
host
string
The target hostname or IP address to check (e.g., "localhost", "192.168.1.1").
port
number
The TCP port number to test for connectivity.
timeout
number
The maximum time to wait for a connection, in milliseconds.
Returns
A promise that resolves to a MonitorCheckResult containing port details, response time, and status.
Remarks
Uses the https://www.npmjs.com/package/is-port-reachable library to test TCP connectivity to the
given host and port, measuring response time with high-precision
performance.now()
. Debug logging is enabled in development mode. This
function does not mutate state or trigger events; it is intended for use
within repository or service layers that handle orchestration and event
propagation.
On success, resolves to a MonitorCheckResult with status "up"
and
the measured response time. On failure, throws a PortCheckError
containing the error message and response time for use in retry or error
handling logic.
Example
try {
const result = await performSinglePortCheck("example.com", 80, 5000);
console.log(
`Port check result: ${result.status} in ${result.responseTime}ms`
);
} catch (error) {
if (error instanceof PortCheckError) {
console.log(`Port unreachable after ${error.responseTime}ms`);
}
}
Throws
PortCheckError Thrown if the port is not reachable within the timeout, with response time included for diagnostics and retry logic.