Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/esnunes/mar
MAR - Message & Reply - RPC library based on message exchange.
https://github.com/esnunes/mar
Last synced: about 2 months ago
JSON representation
MAR - Message & Reply - RPC library based on message exchange.
- Host: GitHub
- URL: https://github.com/esnunes/mar
- Owner: esnunes
- License: mit
- Created: 2013-06-02T16:09:01.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-08-27T16:25:27.000Z (over 11 years ago)
- Last Synced: 2023-08-24T04:52:49.138Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 137 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MAR
MAR - Message & Reply - RPC library based on message exchange.
## Quick Examples
Usage examples can be found [here](http://github.com/esnunes/mar/tree/master/examples) and below.
### Server
```js
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());
});
```### Client
```js
var Client = require('mar').Client;var c = new Client();
c.on('connect', function ping() {
c.message('ping', new Date().getTime(), function(err, data) {
if (err) return console.log(err);
console.log('pong received at [%s]', new Date(data));
});
});
c.connect({ host: 'localhost', port: 8081 });
```### Server - Authentication
```js
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');
});
```### Client - Authentication
```js
var Client = require('mar').Client;var c = new Client();
c.on('connect', function() {
c.message('mar.auth', 'foobar', function(err, auth) {
if (err) return console.log(err);
console.log(auth);
ping();
});
});function ping() {
c.message('ping', new Date().getTime(), function(err, data) {
if (err) return console.log(err);
console.log('pong received at [%s]', new Date(data));
});
}c.connect({ host: 'localhost', port: 8081 });
```## Download
The source is available for download from
[GitHub](http://github.com/esnunes/mar).
Alternatively, you can install using Node Package Manager (npm):npm install mar
## Future - TODO
There are many thoughts about future features for MAR library. You can find them [here](http://github.com/esnunes/mar/blob/master/TODO.md).