stream-node-ipc
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

stream-node-ipc

node-ipc as Duplex streams

Usage

server

import { getServer, NodeIpcServerDuplex } from 'stream-node-ipc';

const someNodeIPCConfigToOverride = { maxConnections: 12 };
// first parameter here is node-ipc `appspace` parameter
const ipcClient = getServer('magne4000-test-worker', someNodeIPCConfigToOverride);

const newClientConnection = (_data: Buffer, socket: Socket) => {
  // Direct bi-directionnal connection between a client (socket) and this server
  // using node-ipc
  const duplex = new NodeIpcServerDuplex(ipcClient, socket);
  duplex.write(...); // writes to the client via node-ipc
  duplex.on('data', (...) => {
    // Callback called when the client sends data via node-ipc
  })
};

// catch first connection for each client in some way
ipcClient.on('data', newClientConnection);

client

import { getClient, NodeIpcClientDuplex } from 'stream-node-ipc';

const someNodeIPCConfigToOverride = { logger: console.log };
// first parameter here is node-ipc `appspace` parameter
const ipcClient = getClient('magne4000-test-worker', 'myClientId', someNodeIPCConfigToOverride);

const duplex = new NodeIpcClientDuplex(ipcClient);
duplex.write(...); // writes to the server via node-ipc
duplex.on('data', (...) => {
  // Callback called when the server sends data via node-ipc
})

Readme

Keywords

none

Package Sidebar

Install

npm i stream-node-ipc

Weekly Downloads

1

Version

2.1.0

License

MIT

Unpacked Size

51.8 kB

Total Files

7

Last publish

Collaborators

  • magne4000