New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

pinary

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pinary

RPC other TCP/TLS and PubSub

latest
Source
npmnpm
Version
1.4.4
Version published
Maintainers
1
Created
Source

pinary

Node.js CI npm version MIT Licence Dependency Status

Introduction

Yet another RPC client and server, with minimalistic publish/subscribe implementation.

  • Server

    • TCP or TLS, as you want (TLS require certificates, see https://github.com/jfromaniello/selfsigned )
    • Persistant connection
    • Binary frames (fast)
    • Optional ZLIB compression
    • Minimalistic JSON Schema implementation (input integrity)
    • Handle Max Clients
    • Basic publish/subscribe support
  • Client

    • Automatic reconnect
    • Internal RPC calls queue
      • Allow lazy client connect
      • Store calls when not connected and play calls when reconnect

Install

npm install pinary

Server

Server: instantiation

const PinaryServer = require('pinary').server;
const server = new PinaryServer();

// with options (see below)
// const server = new PinaryServer({port:64000});

OptionDefaultNotes
useTLSfalseUse clear TCP or TLS
useZLIBfalseUse ZLIB compression
maxClients (1)10Maximum number of simultaneous TCP connections
timeoutData1000Delay before socket close if no data sent, in milliseconds
host0.0.0.0Listening IP/host
port65000 for TCP, 65001 for TLSListening port
keynullTLS: private key
certnullTLS: public key
canullTLS: certificate authority (string of array of string)
secureProtocolTLSv1_2_methodTLS: cipher
rejectUnauthorizedfalseTLS: allow self signed certificates, or not

(1) under the hood, a "client" is in fact 2 sockets, one for writing, one for reading.

Client

Client: instantiation

const PinaryClient = require('pinary').client;
const client = new PinaryClient(); // auto connect

// with a TCP url
// const client = new PinaryClient('tcp://localhost:64000',[options]);

// with a TLS url
// const client = new PinaryClient('tls://localhost:64000',[options]);
OptionDefaultNote
reconnectInterval500milliseconds
queueSize100store rpc calls limit when not connected/disconnected

Client: trigger a method

// using callback
client.rpc('myMethod', (err, result) => {
    if (err) throw err;
    console.log(result);
});

// using async/await
async function letsgo() {
    let result;
    try {
        result = await client.rpcPromise('myMethod');
    } catch(e) {
        // something wrong
    }
    console.log(result);
}

Note: if not yet connected or while the client is trying to reconnect, RPC calls are stored in a queue and played when client is connected.

Client: events

event nameargumentsNotes
connectedretryCountif retryCount = 0, first connection, else reconnection
disconnected
errorError

Publish/Subscribe (PUBSUB)

Client to clients

const Server = require('pinary').server;
const Client = require('pinary').client;

const server = new Server();
const client1 = new Client();
const client2 = new Client();

const channel = '/myChannel';

server.start();

client1.subscribe('/bla', (data) => {
    console.log(data);
    process.exit();
});

client2.publish('/bla', { foo:'bar' });

Server to clients

const Server = require('pinary').server;
const Client = require('pinary').client;

const server = new Server();
const client = new Client();

const channel = '/myChannel';

server.start();

client.subscribe(channel, (data) => {
    console.log(data);
    process.exit();
});

server.publish(channel, { foo:'bar' });

The actual implementation is minimalistic:

  • a channel is considered as an ID, you cannot use wildcards like redis or faye

TODO

  • finish doc
    • events emitted (server)
    • server methods registration (see test/tests/102.methodExist.js, or examples/ for moment)

Keywords

rpc

FAQs

Package last updated on 30 Aug 2021

Did you know?

Socket

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