Socket
Socket
Sign inDemoInstall

ipc-network

Package Overview
Dependencies
15
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ipc-network

Inter-process communication network, allows multiple node process to exchange messages using unix-socket.


Version published
Weekly downloads
18
increased by5.88%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

ipc-network

Inter-process communication network, allows multiple node process to exchange messages using fast datagram unix-socket. Also support RPC request (command is send to another process, and response is returned as a Promise, resolved when response arrives).

Installation

npm i ipc-network --save

Examples

Start listening for messages
import {IpcNetwork, Message} from "ipc-network";

const ipc = new IpcNetwork('process-A');

ipc.on('error', (error: Error) => {
    console.log(error.message);
});

ipc.on('message', (data: Message) => {
    console.log(`New message from ${data.from}: ${data.message.toString()}`);
});

ipc.startListening();
Sending messages
import {IpcNetwork} from "ipc-network";

const ipc = new IpcNetwork('process-A');

ipc.on('error', (error: Error) => {
    console.log(error.message);
});

ipc.send('example content', 'process-B');
Sending RPC (requesting job)
import {IpcNetwork} from "ipc-network";

const ipc = new IpcNetwork('process-A');

ipc.on('error', (error: Error) => {
    console.log(error.message);
});

ipc.sendRpc('example-job', 'process-B', 500).then((result: Buffer) => {
    console.log(`Received job data: ${result.toString()}`);
}).catch((error: Error) => {
    console.log(error.message);
});
Receiving job
import {IpcNetwork} from "ipc-network";

const ipc = new IpcNetwork('process-B', (jobName: string, from: string) => {
    console.log(`Received new job "${jobName}" from: ${from}`);

    return Buffer.from('example jpb results!');
});

ipc.on('error', (error: Error) => {
    console.log(error.message);
});

ipc.startListening();

Additional information

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

GPL-3.0

Keywords

FAQs

Last updated on 22 Mar 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