MCPcopy Create free account
hub / github.com/Noumena-Network/code / checkIdeConnection

Function checkIdeConnection

src/utils/ide.ts:423–454  ·  view source on GitHub ↗

* Checks if the IDE connection is responding by testing if the port is open * @param host Host to connect to * @param port Port to connect to * @param timeout Optional timeout in milliseconds (defaults to 500ms) * @returns true if the port is open, false otherwise

(
  host: string,
  port: number,
  timeout = 500,
)

Source from the content-addressed store, hash-verified

421 * @returns true if the port is open, false otherwise
422 */
423async function checkIdeConnection(
424 host: string,
425 port: number,
426 timeout = 500,
427): Promise<boolean> {
428 try {
429 return new Promise(resolve => {
430 const socket = createConnection({
431 host: host,
432 port: port,
433 timeout: timeout,
434 })
435
436 socket.on('connect', () => {
437 socket.destroy()
438 void resolve(true)
439 })
440
441 socket.on('error', () => {
442 void resolve(false)
443 })
444
445 socket.on('timeout', () => {
446 socket.destroy()
447 void resolve(false)
448 })
449 })
450 } catch (_) {
451 // Invalid URL or other errors
452 return false
453 }
454}
455
456/**
457 * Resolve the Windows USERPROFILE path. WSL often doesn't pass USERPROFILE

Callers 3

cleanupStaleIdeLockfilesFunction · 0.85
detectIDEsFunction · 0.85
ide.tsFile · 0.85

Calls 1

resolveFunction · 0.70

Tested by

no test coverage detected