node-mate
node-mate is a library for the MATE protocol, written in JavaScript for node.js.
Features
Distributed
QoS
Easy-to-use
Installation
npm install node-mate
Quick start
Starting the first mate node.
var mate = ; var node = mate; node; node;
Starting another to connect the first node and send a message.
var mate = ; var node = mate; node; node;
You can run these code online!
API
mate.createNode()
mate.Node#send()
mate.Node#end()
mate.createNode([options])
Create a mate node by the given options and returns the node.
options
is the mate node options, including:networkPort
: Port of the mate node listening, default2015
rootNode
: Address of the first connecting node when the node started, it's a object like:{ip: '127.0.0.1', port: 2015}
nodeId
: the node id, default is a random string generated by uuidnodeInfoFile
: the file that stored the node id, for reuse
mate.Node#send(nodeId, message, [callback])
Send a message.
nodeId
: the node id to send to,String
message
: the message to send to,String
,Buffer
orObject
callback
: fired on sended
mate.Node#end()
Shut down the node.
Event
'listening'
'root_connected'
'message'
'root_disconnect'
'net_error'
'data_error'
'net_close'
'listening'
function() {}
Emitted on successful listening on the node port
'root_connected'
function(rootNode) {}
Emitted when connected to the root node
rootNode
: Information of the root node, including id, address and so on,Object
'message'
function(fromNode, message) {}
Emitted when receive a message
fromNode
: Information of the node that send message, including id, address and so on,Object
message
: message of recevied,String
,Buffer
orObject
'root_disconnect'
function(rootNode) {}
Emitted after lost the connection with the root node
rootNode
: Information of the root node, including id, address and so on,Object
'net_error'
function(error) {}
Emitted when the node cannot listening.
'data_error'
function(error) {}
Emitted when a parsing error occurs.
'net_close'
Emitted when the node shut down.
Code contributions
By contributing code to the project in any form, including sending a pull request via Github, a code fragment or patch via email.
License
MIT