MCPcopy Create free account
hub / github.com/Marus/cortex-debug / isPortInUseEx

Method isPortInUseEx

src/remote/src/tcpportscanner.ts:97–112  ·  view source on GitHub ↗

* Checks to see if the port is in use by creating a server on that port if a localhost or alias * or try to connect to an existing server. * * If we think it is a localhost, It tries to make sure it and its aliases are all free. For * instance 0.0.0.0, 127.0.0.1, ::1 are true al

(port: number, _host: string)

Source from the content-addressed store, hash-verified

95 * @param host host ip address to use. Ignored. All loopback addresses are checked
96 */
97 public static isPortInUseEx(port: number, _host: string): Promise<boolean> {
98 const tries = TcpPortScanner.getLocalHostAliases();
99 const promises = tries.map((host) => TcpPortScanner.isPortInUse(port, host));
100
101 return new Promise(async (resolve, reject) => {
102 const results = await Promise.all(promises.map(p => p.then(x => x).catch(e => e)));
103 ConsoleLog(`isPortInUseEx: Results ${results}`);
104 for (const r of results) {
105 if (r !== false) {
106 resolve(true);
107 return;
108 }
109 resolve(false);
110 }
111 });
112 }
113
114 /**
115 * Scan for free ports (no one listening) on the specified host.

Callers 2

nextMethod · 0.45
findFreePortsSyncMethod · 0.45

Calls 3

ConsoleLogFunction · 0.70
getLocalHostAliasesMethod · 0.45
isPortInUseMethod · 0.45

Tested by

no test coverage detected