IPCEVT - An IPC event system over socket
This module is designed to provide simple event driven ipc system over native nodejs socket module.
How to install ?
Run the following command to install the module.
npm install ipcevt
Note that this library is written using es6 modules. Please remember to use following nodejs option to use the module
node --experimental-modules [your boot script path]
How to use ?
Server
The ipcevt server is designed as a simple broadcasting server that only receive connection and broadcast events among the clients.
Example
import crypto from "crypto";
import {IPCEvtServer} from "ipcevt";
(new IPCEvtServer())
.on( 'connected', (socket)=>{
socket.id = crypto.randomBytes(20).toString('hex');
console.log( `${socket.id} is connected!` );
})
.on( 'disconnected', (socket)=>{
console.log( `${socket.id} is disconnected!` );
})
.on( 'netevt', (socket, event, evt_args)=>{
console.log( `Receiving ${event} from ${socket.id} (contains ${evt_args.length} arguments)` );
})
.listen( 12334, 'localhost' );
Client
The ipcevt client is designed to behave like normal event emitters.
Example
import {IPCEvtClient} from "ipcevt";
const Client = new IPCEvtClient();
Client._serializer = (input)=>{
return Buffer.from(JSON.stringify(input), 'utf8');
};
Client._deserializer = (input)=>{
return JSON.parse(input.toString('utf8'));
};
Client
.on( 'connected', function() {
console.log( "Client has connected to the server!" );
Client.emit( 'greeting', id, 'Hi! There!!!', {a:1, b:2, c:"123", d:Date.now()} );
})
.on( 'disconnected', function() {
console.log( "Client has disconnected from the server!" );
})
.on( 'greeting', function(...args){
console.log(`Receiving [test-event]: `, ...args);
})
.connect( 12334, 'localhost' );