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
server.js:
var dnode = require('dnode-tarantula');
var server = new dnode.Server({
transform: function (a, b, cb) {
cb(a + b, 'Hello from Spider!');
}
}, {port: 5000, host: 'localhost'});
server.on('connection', function(remote) {
remote.math(1, 2, function(res, hello) {
console.log(res, hello);
});
});
client.js:
var dnode = require('dnode-tarantula');
var client = new dnode.Client({
math: function (a, b, cb) {
cb((a + 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(res, hello) {
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')
- Object api - shared Spider object
- Object options - settings object
{
port: 1337, //default 5000
host: 'node.example.com', // default 'localhost'
auth: function(flyAuth, callback) //default null
}
Api has $
object, which is reserved for internal stuff.
Call method with 'methodname' from Client with id = 'nodeId'.
Return Array of all Client ID`s connected to Server
Broadcast call 'methodname' on all Clients and pass to each arguments
Return ids of all connected clients
server.on('connection', function(remote, client, api) {}); // client connected
server.on('disconnection', function(client) {}); // client disconnected
- Object api - shared Client object
- Object options - settings object
{
port: 1337, //default 5000
host: 'node.example.com', // default 'localhost'
nodeId: 'W00T', //default process.pid
auth: function(callback)//default null
}
server.on('connection', function(remote) {}); // client connected