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 - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

unit_results.txt

0

CONTRIBUTING.md

@@ -0,0 +0,0 @@ [![Build Status](https://travis-ci.org/perspectivus1/udprpc.svg?branch=master)](https://travis-ci.org/perspectivus1/udprpc)

@@ -0,0 +0,0 @@ "use strict";

20

dist/code/UdpRpc.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const url = require("url");
const UdpSocket_1 = require("./UdpSocket");

@@ -50,9 +49,8 @@ const Config_1 = require("./Config");

let id = request.id;
let sourceUrl = url.parse(`http://${rinfo.address}:${rinfo.port}`);
if (id === undefined) {
this._registration(request.method, request.params, sourceUrl, () => { }, () => { });
this._registration(request.method, request.params, rinfo.address, rinfo.port, () => { }, () => { });
}
else {
new Promise((resolve, reject) => {
this._registration(request.method, request.params, sourceUrl, resolve, reject);
this._registration(request.method, request.params, rinfo.address, rinfo.port, resolve, reject);
}).then((response) => {

@@ -68,3 +66,3 @@ let responseInternal = {

};
this._udpSocket.send(JSON.stringify(internalMessage), Number(sourceUrl.port), sourceUrl.hostname);
this._udpSocket.send(JSON.stringify(internalMessage), rinfo.port, rinfo.address);
}).catch((err) => {

@@ -81,3 +79,3 @@ let responseInternal = {

};
this._udpSocket.send(JSON.stringify(internalMessage), Number(sourceUrl.port), sourceUrl.hostname);
this._udpSocket.send(JSON.stringify(internalMessage), rinfo.port, rinfo.address);
});

@@ -114,8 +112,8 @@ }

}
send(method, params, url) {
let promise = this._doSend(method, params, url).then((response) => {
send(method, params, address, port) {
let promise = this._doSend(method, params, address, port).then((response) => {
return response;
}).catch((err) => {
if (err.code === exports._INTERNAL_ERR_TIMEOUT_CODE) {
return this.send(method, params, url);
return this.send(method, params, address, port);
}

@@ -140,3 +138,3 @@ else {

}
_doSend(method, params, url) {
_doSend(method, params, address, port) {
let promise = new Promise((resolve, reject) => {

@@ -146,3 +144,3 @@ let id = UdpRpc.getId();

return new Promise((resolve2, reject2) => {
this._udpSocket.send(JSON.stringify(internalMessage), Number(url.port), url.hostname, (err) => {
this._udpSocket.send(JSON.stringify(internalMessage), port, address, (err) => {
if (err) {

@@ -149,0 +147,0 @@ reject2(err);

@@ -0,0 +0,0 @@ "use strict";

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const url = require("url");
require("mocha");

@@ -13,3 +12,3 @@ require("unit.js");

_udpRpcServer.start();
_udpRpcServer.register((method, params, url, resolve, reject) => {
_udpRpcServer.register((method, params, address, port, resolve, reject) => {
switch (method) {

@@ -33,3 +32,3 @@ case "method1": {

_udpRpcClient.start();
return _udpRpcClient.send("method1", [{ key1: "value1" }], url.parse(`http://127.0.0.1:3000`)).catch((err) => {
return _udpRpcClient.send("method1", [{ key1: "value1" }], `127.0.0.1`, 3000).catch((err) => {
return _udpRpcClient.stop();

@@ -44,3 +43,3 @@ }).then((response) => {

_udpRpcClient.start();
return _udpRpcClient.send("method2", [{ key1: "value1" }], url.parse(`http://127.0.0.1:3000`)).catch((err) => {
return _udpRpcClient.send("method2", [{ key1: "value1" }], `127.0.0.1`, 3000).catch((err) => {
assert.ok(true);

@@ -47,0 +46,0 @@ return _udpRpcClient.stop();

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@

{
"name": "@gobark/udprpc",
"version": "0.0.3",
"version": "0.0.4",
"description": "A UDP-based JSON-RPC 2.0 library for peer-to-peer communications with support for ES6 promises",

@@ -5,0 +5,0 @@ "main": "dist/code/UdpRpc.js",

@@ -16,6 +16,8 @@ [![Build Status](https://travis-ci.org/perspectivus1/udprpc.svg?branch=master)](https://travis-ci.org/perspectivus1/udprpc)

## Usage ##
UdpRpc instance listens to the same port from which it executes requests.
UdpRpc leverages UDP to enable each peer listen to and send requests on the same port.
Even through all peers can send and receive requests -- for the sake of simplicity -- **in the example** below the "cient" sends requests and the "server" receives them.
### Server ###
```
```javascript
const url = require("url");

@@ -25,3 +27,3 @@ // import UdpRpc

// create a new instance of UdpRpc
let udpRpcServer = new UdpRpc(3000);
let udpRpcServer = new UdpRpc(3000); // can be any port
// start listening

@@ -51,3 +53,3 @@ udpRpcServer.start();

### Client ###
```
```javascript
// import UdpRpc

@@ -59,3 +61,4 @@ const UdpRpc = require("UdpRpc");

udpRpcClient.start();
return udpRpcClient.send("sum", [ 1, 2 ], url.parse(`http://127.0.0.1:3000`)).then((response) => {
return udpRpcClient.send("sum", [ 1, 2 ], "127.0.0.1", 3000).then((response) => {
// the server can be any address and port as long as their accessible to the client
console.log(response); // response === 3

@@ -62,0 +65,0 @@ }).catch((err) => {

@@ -0,0 +0,0 @@ {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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