本文整理匯總了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();
}