本文整理匯總了TypeScript中tls.connect函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript connect函數的具體用法?TypeScript connect怎麽用?TypeScript connect使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了connect函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: connect
function connect() {
if (socket != null) return;
statusChatTab.addInfo(`Connecting to ${ircNetwork.host}:${ircNetwork.port}...`);
for (const name in channelChatTabs) channelChatTabs[name].addInfo("Connecting...");
for (const name in privateChatTabs) privateChatTabs[name].addInfo("Connecting...");
socket = tls.connect({ host: ircNetwork.host, port: ircNetwork.port, rejectUnauthorized: false }) as any as net.Socket;
socket.on("error", onSocketError);
irc = SlateIRC(socket);
irc.on("welcome", onWelcome);
irc.on("motd", onMOTD);
irc.on("join", onJoin);
irc.on("part", onPart);
irc.on("nick", onNick);
irc.on("away", onAway);
irc.on("quit", onQuit);
irc.on("data", onData);
irc.on("message", onMessage);
irc.on("notice", onNotice);
irc.on("disconnect", onDisconnect);
irc.nick(settings.nickname);
irc.user(settings.nickname, settings.nickname);
}
示例2: function
_this.resolve(endpoint, function (err, resolved) {
if (!_this.connecting) {
callback(new Error(CONNECTION_CLOSED_ERROR_MSG))
return
}
if (resolved) {
debug('resolved: %s:%s', resolved.host, resolved.port)
if (_this.options.enableTLSForSentinelMode && _this.options.tls) {
Object.assign(resolved, _this.options.tls)
_this.stream = createTLSConnection(resolved)
} else {
_this.stream = createConnection(resolved)
}
_this.sentinelIterator.reset(true)
callback(null, _this.stream)
} else {
const endpointAddress = endpoint.host + ':' + endpoint.port
const errorMsg = err
? 'failed to connect to sentinel ' + endpointAddress + ' because ' + err.message
: 'connected to sentinel ' + endpointAddress + ' successfully, but got an invalid reply: ' + resolved
debug(errorMsg)
eventEmitter('sentinelError', new Error(errorMsg))
if (err) {
lastError = err
}
connectToNext()
}
})
示例3: connect
connect(): void {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
this.socket = tls.connect({
host: this.options.host,
port: this.options.port,
rejectUnauthorized: false
}, () => {
console.log('Connected to ' + this.options.host + ':' + this.options.port);
});
if (this.interval) {
clearInterval(this.interval);
this.interval = null;
}
this.interval = setInterval(() => {
this.emit(new TimerEvent(this));
}, 1000);
this.socket.on('data', (data) => {
var inputString = data.toString().trim();
if (!this.connected) {
console.log('Connecting as ' + this.options.username);
this.sendln('co ' + this.options.username + ' ' + this.options.password);
this.connected = true;
this.emit(new ConnectEvent(this));
return;
}
let input = new Input(this, inputString);
try {
for (var i = 0; i < this.pipes.length; ++i) {
let result = this.pipes[i].pipe(input);
if (result == PipeAction.ABORT) {
return;
} else if (result == PipeAction.STOP) {
break;
}
}
} catch (e) {
console.error(e);
return;
}
this.emit(new InputEvent(this, input));
});
this.socket.on('end', () => {
if (this.interval) {
clearInterval(this.interval);
this.interval = null;
}
this.emit(new DisconnectEvent(this));
console.log('Disconnected from server');
});
}
示例4: clearTimeout
req.on('connect', (res, socket, head) => {
clearTimeout(timer);
const stream: TLSSocket = connect(
{ socket, servername: this.options.servername },
() => next(null, stream)
);
stream.on('error', error => {
next(error);
});
});
示例5: Promise
return new Promise((resolve, reject) => {
const socket = tls.connect({
host: query.hostname,
port: query.port
}, () => {
const peerCertificate = socket.getPeerCertificate();
const validTo = Date.parse(peerCertificate.valid_to);
socket.end();
resolve((validTo - Date.now()) / (24 * 3600 * 1000));
});
socket.on('error', reject);
});
示例6: callback
process.nextTick(() => {
if (!this.connecting) {
callback(new Error(CONNECTION_CLOSED_ERROR_MSG))
return
}
let stream: Socket | TLSSocket
try {
if (options.tls) {
stream = createTLSConnection(connectionOptions)
} else {
stream = createConnection(connectionOptions)
}
} catch (err) {
callback(err)
return
}
this.stream = stream
callback(null, stream)
})
示例7:
//////////////////////////////////////////////////
/// TLS tests : http://nodejs.org/api/tls.html ///
//////////////////////////////////////////////////
namespace tls_tests {
var ctx: tls.SecureContext = tls.createSecureContext({
key: "NOT REALLY A KEY",
cert: "SOME CERTIFICATE",
});
var blah = ctx.context;
var connOpts: tls.ConnectionOptions = {
host: "127.0.0.1",
port: 55
};
var tlsSocket = tls.connect(connOpts);
}
////////////////////////////////////////////////////
/// Http tests : http://nodejs.org/api/http.html ///
////////////////////////////////////////////////////
namespace http_tests {
{
// Status codes
var codeMessage = http.STATUS_CODES['400'];
var codeMessage = http.STATUS_CODES[400];
}
{
var agent: http.Agent = new http.Agent({
示例8: function
////////////////////////////////////////////////////
/// TLS tests : http://nodejs.org/api/tls.html
////////////////////////////////////////////////////
var ctx: tls.SecureContext = tls.createSecureContext({
key: "NOT REALLY A KEY",
cert: "SOME CERTIFICATE",
});
var blah = ctx.context;
var tlsOpts: tls.TlsOptions = {
host: "127.0.0.1",
port: 55
};
var tlsSocket = tls.connect(tlsOpts);
////////////////////////////////////////////////////
// Make sure .listen() and .close() retuern a Server instance
http.createServer().listen(0).close().address();
net.createServer().listen(0).close().address();
var request = http.request('http://0.0.0.0');
request.once('error', function () {});
request.setNoDelay(true);
request.abort();
////////////////////////////////////////////////////
/// Http tests : http://nodejs.org/api/http.html
示例9: createSecureContext
import { createSecureContext, SecureContext, ConnectionOptions, connect, getCiphers, DEFAULT_ECDH_CURVE, createServer, TLSSocket } from "tls";
import * as fs from "fs";
{
const ctx: SecureContext = createSecureContext({
key: "NOT REALLY A KEY",
cert: "SOME CERTIFICATE",
});
const blah = ctx.context;
const connOpts: ConnectionOptions = {
host: "127.0.0.1",
port: 55
};
const tlsSocket = connect(connOpts);
const ciphers: string[] = getCiphers();
const curve: string = DEFAULT_ECDH_CURVE;
}
{
const _server = createServer();
_server.addContext("example", {
cert: fs.readFileSync("cert_filepath"),
key: fs.readFileSync("key_filepath")
});
}
{
let _server = createServer({});