mar

MAR - Message & Reply, is a RPC library based on message exchange.

MAR

MAR - Message & Reply - RPC library based on message exchange.

Usage examples can be found here and below.

var Server = require('mar').Server;
 
var s = new Server(8081);
s.on('ping', function(msg) {
  console.log('ping sent at [%s]', new Date(msg.data));
  if (msg.reply) msg.reply(null, new Date().getTime());
});
var Client = require('mar').Client;
 
var c = new Client();
c.on('connect', function ping() {
  c.message('ping', new Date().getTime(), function(errdata) {
    if (err) return console.log(err);
    console.log('pong received at [%s]', new Date(data));
  });
});
c.connect({ host: 'localhost', port: 8081 });
var Server = require('mar').Server;
 
var s = new Server(8081);
s.on('ping', function(msg) {
  console.log('ping sent at [%s]', new Date(msg.data));
  if (msg.reply) msg.reply(null, new Date().getTime());
});
 
s.on('mar.auth', function(msg) {
  if (msg.data != 'foobar') return msg.reply('auth denied');
  msg.reply(null, 'auth granted');
});
var Client = require('mar').Client;
 
var c = new Client();
c.on('connect', function() {
  c.message('mar.auth', 'foobar', function(errauth) {
    if (err) return console.log(err);
    console.log(auth);
    ping();
  });
});
 
function ping() {
  c.message('ping', new Date().getTime(), function(errdata) {
    if (err) return console.log(err);
    console.log('pong received at [%s]', new Date(data));
  });
}
 
c.connect({ host: 'localhost', port: 8081 });

The source is available for download from GitHub. Alternatively, you can install using Node Package Manager (npm):

npm install mar

There are many thoughts about future features for MAR library. You can find them here.