UNPKG

ernest

Version:

Web framework for HTTP and HTTPS, using ExpressJS, Session, Mongo, Socket IO, Redis

40 lines (34 loc) 731 B
const ipc = require('node-ipc'); class ServerCommunicationModule { constructor(serverId,serverChannel) { this.serverId = serverId; this.ServerChannel = serverChannel; this.toServerChannel = '1' + this.ServerChannel; this.fromServerChannel = '0' + this.ServerChannel; ipc.config.id = serverId; ipc.config.retry = 1500; ipc.config.silent = true; }; OnData(callback) { ipc.serve(() => ipc.server.on(this.toServerChannel, (message,socket )=> { callback(message,socket); })); }; Start() { ipc.server.start(); }; Send(data,socket) { ipc.server.emit(socket,this.fromServerChannel,data); }; Disconnect(socket) { ipc.disconnect(socket); }; }; module.exports = ServerCommunicationModule