How to use the tcp-port-used.tcpPortUsed function in tcp-port-used

To help you get started, we’ve selected a few tcp-port-used examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Marus / cortex-debug / src / tcpportscanner.ts View on Github external
{
                min: number;			// Starting port number
                max: number;			// Ending port number (inclusive)
                retrieve?: number;		// Number of ports needed
                consecutive?: boolean;
                doLog?: boolean;
            },
        host = TcpPortScanner.DefaultHost, cb = null): Promise {
        let freePorts = [];
        const busyPorts = [];
        const needed = retrieve;
        let error = null;
        if (needed <= 0) {
            return new Promise((resolve) => { resolve(freePorts); });
        }
        const functor = TcpPortScanner.shouldUseServerMethod(host) ? TcpPortScanner.isPortInUseEx : tcpPortUsed.tcpPortUsed;
        for (let port = min; port <= max; port++) {
            if (needed <= 0) {
                return;
            }
            const startTime = process.hrtime();
            await functor(port, host)
                .then((inUse) => {
                    const endTime = process.hrtime(startTime);
                    if (inUse) {
                        busyPorts.push(port);
                    } else {
                        if (consecutive && (freePorts.length > 0) &&
                            (port !== (1 + freePorts[freePorts.length - 1]))) {
                            if (doLog) {
                                console.log('TcpPortHelper.finnd: Oops, reset for consecutive requirement');
                            }

tcp-port-used

A simple Node.js module to check if a TCP port is already bound.

MIT
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis