npm.io
0.0.3 • Published 5 years ago

rpcsocketlib

Licence
MIT
Version
0.0.3
Deps
4
Size
6 kB
Vulns
2
Weekly
0

rpcsocketlib

install

yarn add rpcsocketlib

server.js


const { socketServer } = require('rpcsocketlib');

(async () => {
  await socketServer(4001);
})();
provider.js

const { socketConsume } = require('rpcsocketlib');

socketConsume('http://localhost:4001', 'test-channel', async (body) => {
  console.log(body);
  return body;
});
consumer.js

const { socketRequest } = require('rpcsocketlib');

(async () => {
  const res = await socketRequest('http://localhost:4001', 'test-channel', { message: 'surprise motherfucker' });
  console.log(res);
})();

usage

socketRequest (uri, channel, body, config)

  • uri : socket server url, ex : http://localhost:4001
  • channel : target client channel
  • body : data, type : object
  • config : options [timeout : int , noReply : bool]

socketConsume (uri, channel, cb)

  • uri : socket server url, ex : http://localhost:4001
  • channel : incoming data channel
  • cb : callback, ex : cb(body) {}