本文整理汇总了TypeScript中net.connect函数的典型用法代码示例。如果您正苦于以下问题:TypeScript connect函数的具体用法?TypeScript connect怎么用?TypeScript connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: reconnect
const module: reconnect.CustomModule<NetConnectOpts | string | number, Socket> = reconnect(arg => {
// TS can't resolve passing even the simplest union types to function overloads :-/
// (see TS issue #14107)
if (typeof arg === "string") {
return connect(arg);
} else if (typeof arg === "number") {
return connect(arg);
} else {
return connect(arg);
}
});
示例2: tryToConnect
function tryToConnect() {
if (timedOut) {
return;
}
var socket = net.connect({ port: port }, () => {
if (timedOut) {
return;
}
resolve();
socket.end();
clearTimeout(handle);
});
socket.on("error", error => {
if (timedOut) {
return;
}
if (error.code === "ECONNREFUSED" && !timedOut) {
setTimeout(() => {
tryToConnect();
}, 10);
return;
}
clearTimeout(handle);
reject(`Connection failed due to ${JSON.stringify(error)}`);
});
}
示例3: sendMessage
public sendMessage(message: ExtensionMessage, args?: any[]): Q.Promise<any> {
let deferred = Q.defer<any>();
let messageWithArguments: MessageWithArguments = { message: message, args: args };
let body = "";
let pipePath = HostPlatform.getExtensionPipePath();
let socket = net.connect(pipePath, function() {
let messageJson = JSON.stringify(messageWithArguments);
socket.write(messageJson);
});
socket.on("data", function(data: any) {
body += data;
});
socket.on("error", function(data: any) {
deferred.reject(new Error("An error ocurred while handling message: " + ExtensionMessage[message]));
});
socket.on("end", function() {
try {
if (body === ErrorMarker) {
deferred.reject(new Error("An error ocurred while handling message: " + ExtensionMessage[message]));
} else {
let responseBody: any = body ? JSON.parse(body) : null;
deferred.resolve(responseBody);
}
} catch (e) {
deferred.reject(e);
}
});
return deferred.promise;
}
示例4: tryToConnect
function tryToConnect() {
if (timedOut) {
return;
}
var socket = net.connect({ port: port }, () => {
if (timedOut) {
return;
}
socket.end();
clearTimeout(handle);
resolve();
});
socket.on("error", error => {
if (timedOut) {
return;
}
if (error.code === "ECONNREFUSED" && !timedOut) {
setTimeout(() => { tryToConnect(); }, 10);
return;
}
clearTimeout(handle);
if (error && error.message) {
error.message = `connection failed (${error.message})`;
}
reject(error);
});
}
示例5: if
const checkServer = () => {
if (all_done || server_ready) {
if (client != null) {
client.destroy()
client = null
}
} else if (num_server_attempts > (server_timeout_millis / 100)) {
promise.reject(new Error("Failed to connect to the server"))
} else if (client != null) {
// still waiting on a client we already have...
setTimeout(checkServer, 100)
} else {
num_server_attempts = num_server_attempts + 1
client = net.connect(port, 'localhost')
client.on('error', () => {
client!.destroy()
client = null
if (!(all_done || server_ready))
setTimeout(checkServer, 100)
})
client.on('connect', () => {
client!.destroy()
client = null
server_ready = true
setTimeout(runF, 0)
})
}
}
示例6: connect
return new Promise<void>((resolve, reject) => {
var client: Socket = connect(port, () => {
console.log('connected to firefox');
this._state = 'connected';
this.setupSocket(client);
resolve();
});
});
示例7: connectToPort
public async connectToPort(data: Mobile.IConnectToPortData): Promise<net.Socket> {
try {
const socket = net.connect(data.port);
return socket;
} catch (e) {
this.$logger.debug(e);
}
}
示例8:
let serverOptions = () => {
// Connect to language server via socket
let socket = net.connect(connectionInfo);
let result: StreamInfo = {
writer: socket,
reader: socket
};
return Promise.resolve(result);
};
示例9:
let serverInfo = () => {
// Connect to the language server via a socket channel
let socket = net.connect(serverOptions);
let result: StreamInfo = {
writer: socket,
reader: socket
}
return Promise.resolve(result);
}
示例10: Promise
return new Promise((resolve, reject) => {
const socket = net.connect(8899, device.config.host, (err: any) => {
if (err) return reject(err)
socket.write(new Buffer(fullCommand), (err: any) => {
socket.destroy()
if (err) return reject(err)
resolve()
})
})
})