npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ac-noderpc

v1.0.3

Published

A simple, fast RPC for Node.JS

Downloads

8

Readme

ac-noderpc

A simple, fast RPC for Node.JS

Install

npm install ac-noderpc

Server

Create RPC server:

var noderpc = require('ac-noderpc')
var rpc_server = new noderpc.ServerRPC();

Methods:

  • publish([name,] function) - Publish a function to be exposed over RPC.

  • run(opt) - Run RPC server.

      opt {
      	type    :   'tcp',
      	host	:   '0.0.0.0',
      	port    :   12345,
      	auth    :   'your password'
      }

Full example:

var noderpc = require('ac-noderpc')
var rpc_server = new noderpc.ServerRPC();

function sum() {
	var ret = arguments[0];     /* first argument is return callback. */
    var s = 0;
    for ( var i = 1; i < arguments.length; i++) {
        s += arguments[i];
    }

    ret(s);
};
rpc_server.publish(sum);

function test(ret) {
	console.log('Just test, no return.');
	ret(null);		/* return callback is required otherwise client will receive a timeout error.  */
};
rpc_server.publish(test);

rpc_server.publish('add', function(ret, a, b) {
    ret(a + b);
});

rpc_server.publish('getobj', function(ret) {
    ret({
        a : 'abc',
        d : 'cde',
        c : [1, 2, 3]
    }, 4, 5, 6);
});

rpc_server.run({
    type    :   'tcp',
    port    :   12345,
    auth    :   'abcdef'
});

Client

Create RPC client

var noderpc = require('ac-noderpc')
var rpc_client = new noderpc.ClientRPC();

Events:

  • error - When an error occurs.
  • connected - When the socket has connected to the RPC server.
  • disconnected - When disconnected from the server.
  • ready - When all the remote functions has been loaded.

Properties:

  • event - The event listener.
  • timeout - The timeout for RPC wait. default: 5000

Methods:

  • tryConnect(opt) - Try to connect to the RPC server, it will automatically reconnect to the RPC server when the RPC server is unavailable.

      opt {
      		type    :   'tcp',
      		host	:   '0.0.0.0',
      		port    :   12345,
      		auth    :   'your password'
      }

Full example:

var noderpc = require('ac-noderpc')
var rpc_client = new noderpc.ClientRPC();

rpc_client.event.on('error', function(err) {
    console.log(err);
});
rpc_client.event.on('connected', function() {
    console.log('connected');
});
rpc_client.event.on('disconnected', function() {
    console.log('disconnected');
});
rpc_client.event.on('ready', function() {
    rpc_client.sum(function(err, result) {
        if ( err ) {
            console.log(err);
        } else {
            console.log(result);
        }
    }, 1, 2, 3, 4);

	rpc_client.test(function(err, result) {
        console.log('test: ' + err);
        console.log('test: ' + result);
    });	

    rpc_client.add(function(err, result) {
        if ( err ) {
            console.log(err);
        } else {
            console.log(result);
        }
    }, 5, 7);

	rpc_client.getobj(function(err, obj, a, b, c) {
        console.log('getobj: ' + err);
        console.log('getobj: ' + JSON.stringify(obj));
        console.log('getobj: ' + a + ', ' + b + ', ' + c);
    });

});

rpc_client.tryConnect({
    type    :   'tcp',
    host    :   '127.0.0.1',
    port    :   12345,
    auth    :   'abcdef'
});

Proxy

Create RPC Proxy

var noderpc = require('ac-noderpc')
var rpc_proxy = new noderpc.ProxyRPC();

Events:

  • proxy_valid - When one of the client has connected to the RPC server.
  • proxy_invalid - When all of the client has disconnected from the server.
  • error - When an error occurs.
  • connected - When the client has connected to the RPC server.
  • disconnected - When the client has disconnected from the server.
  • ready - When the client has ready.

Properties:

  • event - The event listener.

Methods:

  • addHost(opt) - Add RPC host to the proxy.

  •   opt {
      		type    :   'tcp',
      		host	:   '0.0.0.0',
      		port    :   12345,
      		auth    :   'your password',
      		priority : 1
      }
  • isValid() - Check the proxy is valid.

Full example:

var noderpc = require('ac-noderpc')
var rpc_proxy = new noderpc.ProxyRPC();

rpc_proxy.event.on('proxy_valid', function() {
    console.log('Proxy Valid.');

    rpc_proxy.sum(function(err, result) {
        if ( err ) {
            console.log(err);
        } else {
            console.log(result);
        }
    }, 1, 2, 3);
});

rpc_proxy.event.on('proxy_invalid', function() {
    console.log('Proxy Invalid.');
});

rpc_proxy.event.on('error', function(err, client) {
    console.log('Error: ' + err);
});

rpc_proxy.addHost({
    type    :   'tcp',
    host    :   '127.0.0.1',
    port    :   12345,
    auth    :   'abcdef',
    priority : 1
});
rpc_proxy.addHost({
    type    :   'tcp',
    host    :   '127.0.0.1',
    port    :   12345,
    auth    :   'abcdef',
    priority : 1
});

Todo

  • Benchmark
  • Transport - Redis
  • Transport - UDP