本文整理汇总了TypeScript中net.Server类的典型用法代码示例。如果您正苦于以下问题:TypeScript Server类的具体用法?TypeScript Server怎么用?TypeScript Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Server类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: bind
/**
* Binds Http/Https server to the LegacyPlatformProxifier.
* @param server Server to bind to.
*/
public bind(server: Server) {
const oldServer = this.server;
this.server = server;
for (const [eventName, eventHandler] of this.eventHandlers) {
if (oldServer !== undefined) {
oldServer.removeListener(eventName, eventHandler);
}
this.server.addListener(eventName, eventHandler);
}
}
示例2: Promise
return new Promise((resolve) => {
this.server = createServer((socket:Socket) => {
socket.on("data", (data) => {
console.log(data);
});
socket.on("close", () => {
console.log("disconnected");
});
});
this.server.on("error", (error: Error) => {
console.log(error);
});
this.server.listen(
this.port,
this.address,
() => {
resolve();
}
);
});
示例3: it
it("Does not get enough keep alive", function(done) {
let serverSocket: SocketHandler = null;
let count = 0;
let server: Server = net.createServer(function(socket: Socket) {
serverSocket = new SocketHandler(socket, function () {
count++;
console.log("Count: " + count);
if (count < 10) {
serverSocket.send(new SocketMessage(Global.KeepAliveMessage));
} else {
// serverSocket.disconnect();
}
});
}).listen(9000);
let socket = net.connect(9000, "localhost", function () {
let handler = new SocketHandler(socket, function () {
keepAlive.received();
});
let keepAlive = new KeepAlive(handler);
keepAlive.pingPeriod = 50;
keepAlive.warningThreshold = 10;
keepAlive.windowPeriod = 1000;
let gotError = false;
keepAlive.start(function () {
if (gotError) {
return;
}
gotError = true;
// This should get hit
keepAlive.stop();
socket.end();
server.close(function () {
done();
});
});
});
});
示例4: constructor
constructor(private readonly log: Logger, private readonly server: Server) {
super();
// HapiJS expects that the following events will be generated by `listener`, see:
// https://github.com/hapijs/hapi/blob/v14.2.0/lib/connection.js.
this.eventHandlers = new Map(
ServerEventsToForward.map(eventName => {
return [
eventName,
(...args: any[]) => {
this.log.debug(`Event is being forwarded: ${eventName}`);
this.emit(eventName, ...args);
},
] as [string, (...args: any[]) => void];
})
);
for (const [eventName, eventHandler] of this.eventHandlers) {
this.server.addListener(eventName, eventHandler);
}
}
示例5: Promise
return new Promise((resolve, reject) => {
this.server.listen(
port,
host,
(err: Error) => (err ? reject(err) : resolve())
)
})
示例6: getConnections
/**
* Neither new nor legacy platform should use this method directly.
*/
public getConnections(callback: (error: Error | null, count?: number) => void) {
this.log.debug('"getConnections" has been called.');
// This method is used by `even-better` (before we start platform).
// It seems that the latest version of parent `good` doesn't use this anymore.
this.server.getConnections(callback);
}
示例7: getConnections
/**
* Neither new nor legacy platform should use this method directly.
*/
public getConnections(callback: (error: Error | null, count?: number) => void) {
// This method is used by `even-better` (before we start platform).
// It seems that the latest version of parent `good` doesn't use this anymore.
if (this.server) {
this.server.getConnections(callback);
} else {
callback(null, 0);
}
}
示例8: done
keepAlive.start(function () {
if (gotError) {
return;
}
gotError = true;
// This should get hit
keepAlive.stop();
socket.end();
server.close(function () {
done();
});
});
示例9: Promise
await new Promise((resolve) => {
if (server != null) {
server.close(resolve);
}
});
示例10: address
/**
* Neither new nor legacy platform should use this method directly.
*/
public address() {
this.log.debug('"address" has been called.');
return this.server.address();
}