Socket
Socket
Sign inDemoInstall

ipcevt

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ipcevt

A tiny socket based event system


Version published
Weekly downloads
7
increased by16.67%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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)=>{
	// emit when socket is connected to the server!
	// Note that the socket object will be persistent in other events too!
	socket.id = crypto.randomBytes(20).toString('hex');
	console.log( `${socket.id} is connected!` );
})
.on( 'disconnected', (socket)=>{
	// emit when socket is disconnected from the server!
	console.log( `${socket.id} is disconnected!` );
})
.on( 'netevt', (socket, event, evt_args)=>{
	// evt_args are raw buffers, you can manipulate if you want!
	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();

// Register the central serializer to serialize each event argument passed into emit function
Client._serializer = (input)=>{
    return Buffer.from(JSON.stringify(input), 'utf8');
};

// Register the central deserializer to automatically deserialize evey event arguments
Client._deserializer = (input)=>{
    return JSON.parse(input.toString('utf8'));
};


Client
.on( 'connected', function() {
	console.log( "Client has connected to the server!" );
    
    // Note that the input must be a Buffer or an error will be thrown
    // You can register the _serializer is to preprocess each argument!
	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){
    // The arguments will be Buffer if the _deserializer is not registered!
	console.log(`Receiving [test-event]: `, ...args);
})
.connect( 12334, 'localhost' );

Keywords

FAQs

Last updated on 29 Apr 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc