Hi Ernie,
Quick response as I'm just going to bed.
Subscribing is fine from a browser so if say you are connecting to a
broker you can happily do a receive with an address like say localhost
or whatever, but a browser can't really act as a "server" - you are
clearly trying to get your browser to do a socket listen (using the
address of the form amqp://~0.0.0.0 )
That's just a typical browser security limitation I'm afraid and
something in browser WebSockets don't support.
It's not a defect, just a limitation.
Now technically it's something that just might be possible with WebRTC,
as it happens emscripten supports a WebRTC transport too, but I've not
tried it myself (on my TODO list) but the bottom line is yeah you're
mileage is going to be limited by the art of what's actually possible in
a browser, but as I've mentioned previously the Java Broker supports
WebSocket natively, I've supplied a fairly trivially simple node.js
based WebSocket<->TCP Socket proxy and also you can fairly easily stand
up a node based proton intermediary so not having browser peer to
browser peer is probably not a huge issue (though proving AMQP over
WebRTC would be pretty cool and as I say it *should* work I've just not
got round to trying it).
HTH
Frase
On 04/09/14 21:43, Ernest Allen wrote:
I'm getting an error when trying to receive messages from within a browser. The same code
runs fine when run from the command line using "node".
The error message is:
Module.MessengerError {name: "MessengerError", message: "listen: Not
supported", constructor: function, toString: function}
The error happens when calling messenger.subscribe(address);
Is it the case that subscribing is actually not supported from within a
browser, or am I possibly doing something wrong?
I basically just took the code from recv.js and put it in a HTML page.
Here is the code:
<!DOCTYPE html> <!-- HTML5 doctype -->
<html>
<head>
<title>Simple Proton Messenger Send Example</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<script type="text/javascript"
src="../../../node_modules/qpid-proton/lib/proton.js"></script>
<script type="text/javascript">
var address = "amqp://~0.0.0.0";
var message = new proton.Message();
var messenger = new proton.Messenger();
var pumpData = function() {
while (messenger.incoming()) {
var t = messenger.get(message);
console.log("Address: " + message.getAddress());
console.log("Subject: " + message.getSubject());
// body is the body as a native JavaScript Object, useful for most
real cases.
//console.log("Content: " + message.body);
// data is the body as a proton.Data Object, used in this case because
// format() returns exactly the same representation as recv.c
console.log("Content: " + message.data.format());
messenger.accept(t);
}
};
console.log("address = '" + address + "'");
messenger.setIncomingWindow(1024);
messenger.on('error', function(error) {console.log(error);});
messenger.on('work', pumpData);
messenger.start();
messenger.subscribe(address);
messenger.recv(); // Receive as many messages as messenger can buffer.
</script>
</head>
<body>
</body>
</html>
Regards,
-Ernie