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
Features
- Automatic reconnection
- bi-direction and poly-direction communication
- Events
Install
npm install dnode-tarantula
Examples
Also check examples
server.js:
var dnode = ;var server ={;}port: 5000 host: 'localhost';server;
client.js:
var dnode = ;var client ={;}port: 5000 host: 'localhost' nodeId: 'Fly1';client;
output:
node server.js &
node client.js &
3 'Hello from Spider!'
6 'Hello from Fly! My name: Fly1'
Methods
var dnode =
API
Server
var server = dnode;
- Object api - shared server methods object
- Object options - settings object
port: 1337 //default: 5000 host: 'node.example.com' // default: 'localhost' , // default: null id: '1337', // any string. Default: random shortid store: new dnode.stores.redis({ pub: redis sub: redis client: redis }) // 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'.
api.$.ids(callback)
- Function callback - callback
Return Array of all Client ID`s that are connected to Server
server.update(id)
Update server API to client with id == id
server.broadcast(methodname, [arguments])
- String methodname - name of method
- Array arguments - arguments, that should be passed to remote function
Broadcast a function call to all clients.
server.ids()
Return ids of all connected clients
Events
server; // client connectedserver; // client disconnected
Client
var client = dnode;
- 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
client.update()
Call this method after updating your API object, and changes will propagate to server.
Events
client; // client remote methods are readyclient; // ping packet sentclient; // well... A ping timeout!client; // emitted when ping reply arrives