dnode-tarantula

asynchronous rpc system for node.js, bi-direction and poly-direction communication...

dnode-tarantula

dnode-tarantula is an asynchronous rpc and event system for node.js based on dnode-protocol and TCP sockets. This is fork of dnode-spider

  • Automatic reconnection
  • bi-direction and poly-direction communication
  • Events
npm install dnode-tarantula

Also check examples

server.js:

var dnode = require('dnode-tarantula');
 
var server = new dnode.Server({
    transformfunction (abcb) {
        cb(+ b, 'Hello from Spider!');
    }
}, {port: 5000, host: 'localhost'});
 
server.on('connection', function(remote) {
    remote.math(1, 2, function(reshello) {
        console.log(res, hello);
    });
});
 

client.js:

var dnode = require('dnode-tarantula');
 
var client = new dnode.Client({
    mathfunction (abcb) {
        cb((+ b) * 2, 'Hello from Fly! My name: '+client.nodeId);
    }
}, {port: 5000, host: 'localhost', nodeId: 'Fly1'});
 
client.on('connection', function(remote) {
    remote.transform(1, 2, function(reshello) {
        console.log(res, hello);
    });
});
 

output:

node server.js &
node client.js &
3 'Hello from Spider!'
6 'Hello from Fly! My name: Fly1'
var dnode = require('dnode-tarantula')

API

var server = dnode.Server(api, options);
  • Object api - shared server methods object
  • Object options - settings object
{
    port: 1337, //default: 5000 
    host: 'node.example.com', // default: 'localhost' 
    authfunction(flyAuthcallback), // default: null 
    id: '1337', // any string. Default: random shortid 
    store: new dnode.stores.redis({
        pub: redis.createServer(),
        sub: redis.createServer(),
        client: redis.createServer()
    }), // default: memory store 
    pingInterval: 15000, // Any number in ms. default: 10000 
}

Api object has $ object, which is reserved for internal stuff (Danger Zone™).

Call method with 'methodname' from Client with id = 'nodeId'.

  • Function callback - callback

Return Array of all Client ID`s that are connected to Server

Update server API to client with id == id

  • String methodname - name of method
  • Array arguments - arguments, that should be passed to remote function

Broadcast a function call to all clients.

Return ids of all connected clients

server.on('connection', function(remoteclientapi) {});  // client connected 
server.on('disconnection', function(client) {});        // client disconnected 
var client = dnode.Client(api, options);
  • Object api - shared Client methods object
  • Object options - settings object
{
    port: 1337, //default: 5000 
    host: 'node.example.com', // default: 'localhost' 
    nodeId: 'W00T', //default: process.pid 
    auth: 'SoSecureKey' //auth key. default: null 
}

Call this method after updating your API object, and changes will propagate to server.

client.on('remote', function(remote) {}); // client remote methods are ready 
client.on('ping', function(client) {}); // ping packet sent 
client.on('ping:timeout', function(client) {}); // well... A ping timeout! 
client.on('ping:reply', function(client) {}); // emitted when ping reply arrives