UNPKG

@shorkiedev/mc-status

Version:

A simple ESM package that can check multiple minecraft server status.

33 lines 942 B
/** * TCP Ping */ import { Socket } from "net"; /** * @param host - Hostname or IP * @param port - TCP port to ping (required) * @param timeout - Timeout in ms (default 3000) */ export async function tcpPing(host, port, timeout = 3000) { return new Promise((resolve) => { const socket = new Socket(); let called = false; const start = Date.now(); const fail = () => { if (!called) { called = true; resolve({ online: false, latency: null }); socket.destroy(); } }; socket.setTimeout(timeout, fail); socket.once("error", fail); socket.connect(port, host, () => { if (!called) { called = true; resolve({ online: true, latency: Date.now() - start }); socket.destroy(); } }); }); } //# sourceMappingURL=tcpPing.js.map