Socket
Socket
Sign inDemoInstall

node-ipc

Package Overview
Dependencies
2
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    node-ipc

A nodejs module for local and remote Inter Process Communication (IPC) uses Unix Sockets for local communication avoiding the network card for lower overhead and latency. ## Solid but, ### Still under development and lacking documentation, but useable.


Version published
Weekly downloads
477K
decreased by-0.22%
Maintainers
1
Install size
68.9 kB
Created
Weekly downloads
 

Package description

What is node-ipc?

The node-ipc package is a Node.js module that provides a simple and flexible way to handle inter-process communication (IPC) in Node.js applications. It supports various types of communication, including local sockets, TCP, and UDP, making it suitable for a wide range of use cases such as microservices, distributed systems, and real-time applications.

What are node-ipc's main functionalities?

Local Socket Communication

This feature allows for communication between processes on the same machine using local sockets. The code sample demonstrates setting up a server that listens for messages and a client that sends and receives messages.

const ipc = require('node-ipc');

ipc.config.id = 'world';
ipc.config.retry = 1500;
ipc.config.silent = true;

ipc.serve(() => {
  ipc.server.on('message', (data, socket) => {
    ipc.log('Received message: ', data);
    ipc.server.emit(socket, 'message', 'Hello from server!');
  });
});

ipc.server.start();

// Client
ipc.connectTo('world', () => {
  ipc.of.world.on('connect', () => {
    ipc.log('Connected to world');
    ipc.of.world.emit('message', 'Hello from client!');
  });

  ipc.of.world.on('message', (data) => {
    ipc.log('Received message: ', data);
  });
});

TCP Communication

This feature enables communication over TCP, allowing processes to communicate over a network. The code sample shows how to set up a TCP server and a client that can send and receive messages.

const ipc = require('node-ipc');

ipc.config.id = 'tcpServer';
ipc.config.retry = 1500;
ipc.config.networkPort = 8000;
ipc.config.silent = true;

ipc.serveNet(() => {
  ipc.server.on('message', (data, socket) => {
    ipc.log('Received message: ', data);
    ipc.server.emit(socket, 'message', 'Hello from TCP server!');
  });
});

ipc.server.start();

// Client
ipc.connectToNet('tcpServer', 8000, () => {
  ipc.of.tcpServer.on('connect', () => {
    ipc.log('Connected to TCP server');
    ipc.of.tcpServer.emit('message', 'Hello from TCP client!');
  });

  ipc.of.tcpServer.on('message', (data) => {
    ipc.log('Received message: ', data);
  });
});

UDP Communication

This feature supports communication over UDP, which is useful for applications that require low-latency communication. The code sample demonstrates setting up a UDP server and a client that can send and receive messages.

const ipc = require('node-ipc');

ipc.config.id = 'udpServer';
ipc.config.retry = 1500;
ipc.config.networkPort = 8001;
ipc.config.silent = true;

ipc.serveUDP(() => {
  ipc.server.on('message', (data, socket) => {
    ipc.log('Received message: ', data);
    ipc.server.emit(socket, 'message', 'Hello from UDP server!');
  });
});

ipc.server.start();

// Client
ipc.connectToUDP('udpServer', 8001, () => {
  ipc.of.udpServer.on('connect', () => {
    ipc.log('Connected to UDP server');
    ipc.of.udpServer.emit('message', 'Hello from UDP client!');
  });

  ipc.of.udpServer.on('message', (data) => {
    ipc.log('Received message: ', data);
  });
});

Other packages similar to node-ipc

Readme

Source

#node-ipc a nodejs module for local and remote Inter Process Communication

npm install node-ipc

this is a new project so more documentation will come


Local IPC

Uses Unix Sockets to give lightning fast communication and avoid the network card to reduce overhead and latency.

Server Example

The server is the process keeping a Unix Socket for IPC open. Multiple sockets can connect to this server and talk to it. It can also broadcast to all clients or emit to a specific client.

var ipc=require('node-ipc');

ipc.config.id   = 'world';
ipc.config.retry= 1500;

ipc.serve(
    function(){
        ipc.server.on(
            'message',
            function(data,socket){
                ipc.log('got a message : '.debug, data);
                socket.emit(
                    'message',
                    data+' world!'
                );
            }
        );
    }
);

ipc.server.start();
Client Example

The client connects to the servers Unix Socket for Inter Process Communication. The socket will recieve events emitted to it specifically as well as events which are broadcast out on the Unix Socket by the server.

var ipc=require('../../../node-ipc');

ipc.config.id   = 'hello';
ipc.config.retry= 1500;

ipc.connectTo(
    'world',
    function(){
        ipc.of.world.on(
            'connect',
            function(){
                ipc.log('## connected to world ##'.rainbow, ipc.config.delay);
                ipc.of.world.emit(
                    'message',
                    'hello'
                )
            }
        );
        ipc.of.world.on(
            'disconnect',
            function(){
                ipc.log('disconnected from world'.notice);
            }
        );
        ipc.of.world.on(
            'message',
            function(data){
                ipc.log('got a message from world : '.debug, data);
            }
        );
    }
);

Remote IPC - coming soon

Uses not yet defined Sockets to give fastest possible communication across the network with the minimum overhead and latency.

Keywords

FAQs

Last updated on 26 Feb 2014

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