Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zerorpc

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zerorpc

A port of ZeroRPC to node.js

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
177
increased by115.85%
Maintainers
1
Weekly downloads
 
Created
Source

zerorpc-node

This is a port of ZeroRPC to node.js. We have full client and server support for version 2 of the protocol, however there are issues with legacy support.

This project is alpha.

To install the package:

npm install zerorpc

Servers

To create a new server:

var zerorpc = require("zerorpc");
var server = new zerorpc.Server(context);

The constructor takes in a context object with the functions to expose over RPC. Only functions that do not have a leading underscore will be exposed. Each exposed method must take in a callback as the last argument. This callback is called as callback(error, response, more) when there is a new update, where error is an error object or string, response is the new update, and more is a boolean specifying whether new updates will be available later.

Events:

  • error - When an error occurs.

Methods:

  • bind(endpoint) - Binds the server to the specified ZeroMQ endpoint.
  • connect(endpoint) - Connects the server to the specified ZeroMQ endpoint.
  • close() - Closes the ZeroMQ socket.

Full example:

var zerorpc = require("zerorpc");

var server = new zerorpc.Server({
    addMan: function(sentence, reply) {
        reply(null, sentence + ", man!", false);
    },

    add42: function(n, reply) {
        reply(null, n + 42, false);
    },

    iter: function(from, to, step, reply) {
        for(i=from; i<to; i+=step) {
            reply(null, i, true);
        }

        reply(null, undefined, false);
    }
});

server.bind("tcp://0.0.0.0:4242");

server.on("error", function(error) {
    console.error("RPC server error:", error);
});

Clients

To create a new client:

var zerorpc = require("zerorpc");
var client = new zerorpc.Client(options);

The constructor optionally takes in an options object. Allowable options:

  • timeout (number) - Sets the number of seconds to wait for a response before considering the call timed out. Defaults to 30.

Events:

  • error - When an error occurs.

Methods:

  • bind(endpoint) - Binds the server to the specified ZeroMQ endpoint.
  • connect(endpoint) - Connects the server to the specified ZeroMQ endpoint.
  • close() - Closes the ZeroMQ socket.
  • invoke(method, arguments..., callback) - Invokes a remote method.
    • method is the method name.
    • callback is a method to call when there is an update. This callback is called as callback(error, response, more) when there is a new update, where error is an error object, response is the new update, and more is a boolean specifying whether new updates will be available later.

Full example:

var zerorpc = require("zerorpc");

var client = new zerorpc.Client();
client.connect("tcp://127.0.0.1:4242");

client.on("error", function(error) {
    console.error("RPC client error:", error);
});

client.invoke("iter", 10, 20, 2, function(error, res, more) {
    if(error) {
        console.error(error);
    } else {
        console.log("UPDATE:", res);
    }

    if(!more) {
        console.log("Done.");
    }
});

Keywords

FAQs

Package last updated on 05 Jun 2012

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