WAMP: Difference between revisions
Jump to navigation
Jump to search
(Created page with "WAMP (Web Application Messaging Protocol) is an open WebSocket subprotocol that provides two application messaging patterns in one unified protocol: [[Remote Procedure Cal...") |
(→Extra) |
||
Line 7: | Line 7: | ||
==Extra== |
==Extra== |
||
* WAMP with Arduino Yun http://tavendo.com/blog/post/arduino-yun-with-autobahn/ |
* WAMP with Arduino Yun http://tavendo.com/blog/post/arduino-yun-with-autobahn/ |
||
==[[Node.js]]== |
|||
<pre> |
|||
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(); |
|||
</pre> |
Revision as of 21:07, 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
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();