Paho Javascript client [message #1695350] |
Wed, 13 May 2015 12:48  |
Eclipse User |
|
|
|
Hello All,
I am trying to connect to the online MQTT broker at iot.eclipse.org port 1883 using the javascript client.
However, after using the following code, when I tried to connect to the broker, I get the error : WebSocket connection to 'ws://iot.eclipse.org:1883/mqtt' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET mqttws31.js:980 in the browser console.
// Create a client instance
client = new Paho.MQTT.Client(location.hostname, Number(location.port), "clientId");
// set callback handlers
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
// connect the client
client.connect({onSuccess:onConnect});
// called when the client connects
function onConnect() {
// Once a connection has been made, make a subscription and send a message.
console.log("onConnect");
client.subscribe("/World");
message = new Paho.MQTT.Message("Hello");
message.destinationName = "/World";
client.send(message);
}
// called when the client loses its connection
function onConnectionLost(responseObject) {
if (responseObject.errorCode !== 0) {
console.log("onConnectionLost:"+responseObject.errorMessage);
}
}
// called when a message arrives
function onMessageArrived(message) {
console.log("onMessageArrived:"+message.payloadString);
}
Could someone suggest where I am going wrong.
Regards
Ankur
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05306 seconds