當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript portscanner.checkPortStatus函數代碼示例

本文整理匯總了TypeScript中portscanner.checkPortStatus函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript checkPortStatus函數的具體用法?TypeScript checkPortStatus怎麽用?TypeScript checkPortStatus使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了checkPortStatus函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: init

/**
 * Init app
 */
async function init(): Promise<Config> {
	Logger.info('Welcome to Misskey!');

	(new Logger('Deps')).info(`Node.js ${process.version}`);
	MachineInfo.show();
	EnvironmentInfo.show();
	new DependencyInfo().showAll();

	const configLogger = new Logger('Config');
	let config;

	try {
		config = loadConfig();
	} catch (exception) {
		if (typeof exception === 'string') {
			configLogger.error(exception);
			process.exit(1);
		}
		if (exception.code === 'ENOENT') {
			configLogger.error('Configuration file not found');
			process.exit(1);
		}
		throw exception;
	}

	configLogger.succ('Loaded');

	if (process.platform === 'linux' && !isRoot() && config.port < 1024) {
		Logger.error('You need root privileges to listen on port below 1024 on Linux');
		process.exit(1);
	}

	if (await portscanner.checkPortStatus(config.port, '127.0.0.1') === 'open') {
		Logger.error(`Port ${config.port} is already in use`);
		process.exit(1);
	}

	// Try to connect to MongoDB
	checkMongoDb(config);

	return config;
}
開發者ID:ha-dai,項目名稱:Misskey,代碼行數:45,代碼來源:index.ts

示例2: assert

import * as portscanner from 'portscanner';
declare function assert(cond: boolean): void;

const checkPortCallback = (error: Error | null, status: portscanner.Status) => {
    assert(error === null);
    error && assert(error.message === '');
    assert(status === 'open');
    assert(status === 'closed');
};

const assertStatus = (status: portscanner.Status) => {
    assert(status === 'open');
    assert(status === 'closed');
};

portscanner.checkPortStatus(3000).then(assertStatus);

portscanner.checkPortStatus(3000, '127.0.0.1').then(assertStatus);
portscanner.checkPortStatus(3000, { host: '127.0.0.1' }).then(assertStatus);
portscanner.checkPortStatus(3000, { timeout: 400 }).then(assertStatus);
portscanner.checkPortStatus(3000, checkPortCallback);

portscanner.checkPortStatus(3000, { host: '127.0.0.1' }, checkPortCallback);
portscanner.checkPortStatus(3000, { timeout: 400 }, checkPortCallback);
portscanner.checkPortStatus(3000, '127.0.0.1', checkPortCallback);

portscanner.checkPortStatus(3000, '127.0.0.1', { timeout: 400 }).then(assertStatus);
portscanner.checkPortStatus(3000, '127.0.0.1', { timeout: 400 }, checkPortCallback);

const findPortCallback = (error: Error | null, port: number) => {
    assert(error === null);
開發者ID:Crevil,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:node-portscanner-tests.ts


注:本文中的portscanner.checkPortStatus函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。