I'm trying to connect to rabbitmq through the web. I have to machines, one is used as rabbitmq server with rabbitmq-web-stomp plugin enabled, while the other is used as client.
<!DOCTYPE html>
<meta charset="utf-8" />
<title>Stomp Websocet Exercise </title>
<script language="javascript" type="text/javascript">
var output;
var subscription;
var i=0;
var client;
var on_connect = function() {
writeToScreen('Connected');
}
var on_error = function(error) {
writeToScreen('Error: ' + error.headers.message);
}
var on_disconnect = function(){
writeToScreen('Disconnected');
}
function sendMsg(){
client.send("/topic/test", {priority: 9}, document.getElementById("msg").value);
}
function init() {
output = document.getElementById("output");
writeToScreen('Initializing...');
client = Stomp.over(ws);
client.heartbeat.outgoing=0;
client.heartbeat.incoming=0;
writeToScreen('Connecting...');
client.connect('xxh', 'xxh', on_connect, on_error, '/xxh');
}
function writeToScreen(message) {
var pre = document.createElement("p");
pre.style.wordWrap = "break-word";
pre.innerHTML = message;
output.appendChild(pre);
}
window.addEventListener("load", init, false);
</script>
<h2>Stomp Websocket Test</h2>
<form action="#" onSubmit="sendMsg(); return false;">
<input type="text" name="msg" id="msg" style="width: 300px" />
</form>
<div id="output"></div>
when I open this html file on the server machine, it can successfully connect to rabbitmq and send messages, however, when it is opened on the client machine, it seems that it's stuck when connecting rabbitmq server, as neither on_connect function nor on_error function is invoked.
Why is this happening? Is this due to some cross-domain access restriction? Please help me, Thank you:-)