New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@gobark/udprpc

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gobark/udprpc

A UDP-based JSON-RPC 2.0 library for peer-to-peer communications with support for ES6 promises

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-72.73%
Maintainers
2
Weekly downloads
 
Created
Source

Build Status

UdpRpc

This is a UDP-based JSON-RPC 2.0 library for peer-to-peer communications with support for ES6 promises.

This library is (nearly) compliant with the JSON-RPC 2.0 Specification http://www.jsonrpc.org/specification.

Missing: Support JSON-RPC batch requests and reponses.

Installation

npm install @gobark/udprpc

Usage

UdpRpc instance listens to the same port from which it executes requests.

Server

const url = require("url");
// import UdpRpc
const UdpRpc = require("@gobark/udprpc").UdpRpc;
// create a new instance of UdpRpc
let udpRpcServer = new UdpRpc(3000);
// start listening
udpRpcServer.start();
// handle incoming requests
udpRpcServer.register((method, params, url, resolve, reject) => {
    switch (method) {
        case "sum": {
            if (isNaN(params[0]) || isNaN(params[1])) {
                reject("Parameters must be numbers");
            } else {
                resolve(Number(params[0]) + Number(params[1]));
            }
            break;
        }
        case "concat": {
            resolve(`${params[0]}${params[1]}`);
            break;
        }
    }

    // stop server when needed
    // udpRpcServer.stop();
});

Client

// import UdpRpc
const UdpRpc = require("UdpRpc");
// create a new instance of UdpRpc
let udpRpcClient = new UdpRpc(3001);
// start listening
udpRpcClient.start();
return udpRpcClient.send("sum", [ 1, 2 ], url.parse(`http://127.0.0.1:3000`)).then((response) => {
    console.log(response); // response === 3
}).catch((err) => {
    console.error(err);
}).then(() => {
    // stop client
    udpRpcClient.stop();
});

Contribution guidelines

See CONTRIBUTING.md

Who do I talk to?

FAQs

Package last updated on 22 Aug 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc