WAMP: Difference between revisions
Jump to navigation
Jump to search
| Line 9: | Line 9: | ||
==[[Node.js]]== |
==[[Node.js]]== |
||
http://autobahn.ws/js/gettingstarted.html |
|||
<pre> |
<pre> |
||
npm install autobahn |
|||
</pre> |
|||
<pre> |
|||
var autobahn = require('autobahn') |
|||
var connection = new autobahn.Connection({ |
var connection = new autobahn.Connection({ |
||
url: 'ws://127.0.0.1:9000/', |
url: 'ws://127.0.0.1:9000/', |
||
Revision as of 21:10, 16 November 2014
WAMP (Web Application Messaging Protocol) is an open WebSocket subprotocol that provides two application messaging patterns in one unified protocol: Remote Procedure Calls + Publish-Subscribe
- http://wamp.ws/spec/
- https://github.com/tavendo/WAMP/blob/master/spec/basic.md
- https://github.com/tavendo/WAMP/blob/master/spec/advanced.md
Extra
- WAMP with Arduino Yun http://tavendo.com/blog/post/arduino-yun-with-autobahn/
Node.js
http://autobahn.ws/js/gettingstarted.html
npm install autobahn
var autobahn = require('autobahn')
var connection = new autobahn.Connection({
url: 'ws://127.0.0.1:9000/',
realm: 'realm1'
});
connection.onopen = function (session) {
// 1) subscribe to a topic
function onevent(args) {
console.log("Event:", args[0]);
}
session.subscribe('com.myapp.hello', onevent);
// 2) publish an event
session.publish('com.myapp.hello', ['Hello, world!']);
// 3) register a procedure for remoting
function add2(args) {
return args[0] + args[1];
}
session.register('com.myapp.add2', add2);
// 4) call a remote procedure
session.call('com.myapp.add2', [2, 3]).then(
function (res) {
console.log("Result:", res);
}
);
};
connection.open();
Node-RED
TODO