Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » Paho Javascript client( Error in connection to the MQTT broker)
Paho Javascript client [message #1695350] Wed, 13 May 2015 16:48 Go to next message
ankur bhatia is currently offline ankur bhatiaFriend
Messages: 4
Registered: May 2015
Junior Member
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
Re: Paho Javascript client [message #1695363 is a reply to message #1695350] Wed, 13 May 2015 17:38 Go to previous messageGo to next message
Benjamin Cabé is currently offline Benjamin CabéFriend
Messages: 201
Registered: July 2009
Location: Toulouse, France
Senior Member

The Websocket is running on /ws. You should rather try:

var client = new Paho.MQTT.Client("ws://iot.eclipse.org/ws", "myClientId" + new Date().getTime());


Re: Paho Javascript client [message #1695546 is a reply to message #1695363] Sat, 16 May 2015 08:05 Go to previous message
ankur bhatia is currently offline ankur bhatiaFriend
Messages: 4
Registered: May 2015
Junior Member
Thank you very much for the help Benjamin.
Previous Topic:Paho cannt connect to a wireless network
Next Topic:Not getting Published message from Mqtt Broker in Paho Client
Goto Forum:
  


Current Time: Wed Sep 19 04:44:37 GMT 2018

Powered by FUDForum. Page generated in 0.01773 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top