findFreePort (node/ports.ts)

vscode · extensions/copilot/src/util/vs/base/node/ports.ts · typescript · MIT
email

Utility to find an available TCP port within a range, with timeout and stride options, for use in network services.

// Source: https://github.com/microsoft/vscode | License: MIT | Copyright 2015 - present Microsoft Corporation
// Provided via justclaw.it.com; keep this notice with the code.
//!!! DO NOT modify, this file was COPIED from 'microsoft/vscode'

/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import * as net from 'net';

/**
 * Given a start point and a max number of retries, will find a port that
 * is openable. Will return 0 in case no free port can be found.
 */
export function findFreePort

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key