本文整理匯總了TypeScript中portfinder.getPort函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript getPort函數的具體用法?TypeScript getPort怎麽用?TypeScript getPort使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了getPort函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: Promise
return new Promise((resolve, reject) => {
PortFinder.getPort((err, port) => {
let fatJar = Path.resolve(context.extensionPath, "out", "fat-jar.jar");
let args = [
'-cp', fatJar,
'-Djavacs.port=' + port,
'org.javacs.Main'
];
console.log(javaExecutablePath + ' ' + args.join(' '));
Net.createServer(socket => {
console.log('Child process connected on port ' + port);
resolve({
reader: socket,
writer: socket
});
}).listen(port, () => {
let options = { stdio: 'inherit', cwd: VSCode.workspace.rootPath };
// Start the child java process
ChildProcess.execFile(javaExecutablePath, args, options);
});
});
});
示例2: function
function(callback) {
const host = '0.0.0.0';
getPort({port: 8080, host: host}, function(err, port) {
if (err) { throw err; }
createServer(requestListener).listen(port, host, function(err: any) {
callback(err, `http://${host}:${port}`);
});
});
},
示例3: beforeAll
beforeAll((done) => {
portfinder.getPort((err: Error, p: number) => {
if (err) {
done.fail(err);
} else {
port = p;
server = new MockAppium(port);
server.start();
done();
}
});
});
示例4: Observable
return new Observable(obs => {
portfinder.basePort = basePort;
// tslint:disable:no-any
portfinder.getPort({ port, host }, (err: any, foundPort: number) => {
if (err) {
obs.error(err);
} else if (port !== foundPort && port !== 0) {
// If the port isn't available and we weren't looking for any port, throw error.
obs.error(`Port ${port} is already in use. Use '--port' to specify a different port.`);
} else {
// Otherwise, our found port is good.
obs.next(foundPort);
obs.complete();
}
});
});
示例5: Promise
return new Promise((resolve, reject) => {
PortFinder.getPort((err, port) => {
if (port != PortFinder.basePort) {
console.log("Port in use, connect instead of create.");
let socket = Net.createConnection({port: PortFinder.basePort}, () => {
console.log('connected to server!');
});
socket.on("connect", () => {
resolve({
reader: socket,
writer: socket
});
});
} else {
/*
let fatJar = Path.resolve(context.extensionPath, "out", "fat-jar.jar");
let args = [
'-cp', fatJar,
'-Djavacs.port=' + port,
'org.javacs.Main'
];
console.log(javaExecutablePath + ' ' + args.join(' '));
Net.createServer(socket => {
console.log('Child process connected on port ' + port);
resolve({
reader: socket,
writer: socket
});
}).listen(port, () => {
let options = { stdio: 'inherit', cwd: VSCode.workspace.rootPath };
// Do not start the child java process (debugging)
ChildProcess.execFile(javaExecutablePath, args, options);
});
*/
console.log("cannot connect to language server");
}
});
});
示例6: require
// Start listening
const portfinder = require('portfinder');
portfinder.basePort = clOptions.port;
portfinder.getPort(function (err, port) {
if (err) {
console.error(err);
exit(errorCodes.couldNotListen);
}
/** If the user *did* specify a port and we end up not using it */
if (clOptions.port !== cl.defaultPort
&& port !== clOptions.port) {
console.log(chalk.magenta(`[WEB] WARNING: Desired port is not available so using port ${port}`));
}
server.listen(port, clOptions.host, function(err) {
if (err) {
console.error(err);
exit(errorCodes.couldNotListen);
}
const host = clOptions.host in {'localhost':true,'127.0.0.1':true,'0.0.0.0': true} ? 'localhost' : clOptions.host
console.log(`DASHBOARD:`, chalk.green(`http://${host}:${port}`));
if (clOptions.open) {
open(`http://${host}:${port}`);
}
serverStarted.started();
});
});
/**
* Notify user of updates
*/
示例7: resolve
return new Promise<any>((resolve, reject) => {
portFinder.getPort((err, port) => {
const uberJar = path.resolve(
context.extensionPath,
'out',
UBER_JAR_NAME
);
const javaExecutable = path.resolve(
`${requirementsData.java_home}/bin/java`
);
let args: string[];
if (DEBUG) {
args = [
'-cp',
uberJar,
`-Dapex-lsp.port=${port}`,
'-Ddebug.internal.errors=true',
'-Ddebug.semantic.errors=false',
'-Dtrace.protocol=false',
`-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=${JDWP_DEBUG_PORT}`,
APEX_LANGUAGE_SERVER_MAIN
];
} else {
args = [
'-cp',
uberJar,
`-Dapex-lsp.port=${port}`,
'-Ddebug.internal.errors=true',
'-Ddebug.semantic.errors=false',
APEX_LANGUAGE_SERVER_MAIN
];
}
net
.createServer(socket => {
resolve({
reader: socket,
writer: socket
});
})
.listen(port, () => {
const options = {
cwd: vscode.workspace.rootPath
};
const lspProcess = child_process.spawn(
javaExecutable,
args,
options
);
console.log('PROCESS INFO');
console.log(lspProcess);
lspProcess.stdout.on('data', data => {
APEX_LANGUAGE_SERVER_CHANNEL.appendLine(`${data}`);
});
lspProcess.stderr.on('data', data => {
APEX_LANGUAGE_SERVER_CHANNEL.appendLine(`${data}`);
});
lspProcess.on('close', code => {
APEX_LANGUAGE_SERVER_CHANNEL.appendLine(
`${nls.localize('client_name')} exited with code: ${code}`
);
});
});
});
});
示例8: register
// Setup a socket server
import {register} from "./socket/socketServer";
register(server);
// Start listening
var portfinder = require('portfinder');
portfinder.basePort = clOptions.port;
portfinder.getPort(function (err, port) {
if (err) {
console.error(err);
exit(errorCodes.couldNotListen);
}
server.listen(port, function(err) {
if (err) {
console.error(err);
exit(errorCodes.couldNotListen);
}
console.log(`Dashboard at http://localhost:${port}`);
if (clOptions.open) {
open(`http://localhost:${port}`);
}
serverStarted.started();
});
});
/**
* Notify user of updates
*/
var pkg = require('../package.json');
require('update-notifier')({
pkg,
示例9:
const port = await fromCallback<number>(cb => portfinder.getPort(cb));
示例10: require
import hapi = require("hapi");
import Promise = require("bluebird");
import log = require("./log");
import allRoutes = require("./routes/all");
import todo = require("./routes/todo/items");
var portFinder = require("portfinder");
var server = new hapi.Server();
portFinder.getPort((err, port) => {
log.debug("Fetched port: " + port);
port = port;
startServer(port);
});
function startServer(port: number) {
server.connection({
port: port
});
for (var route in allRoutes) server.route(allRoutes[route]);
server.start(() => {
log.info("Server listening on port " + port);
seedData();
});
}
function seedData() {
var data = [
{ id: 1, message: "first item", isDone: 0 },