0

I've downloaded Mosca (^1.1.2), MQTT (via npm) and Paho. When I create a simple broker as shown here: http://thejackalofjavascript.com/getting-started-mqtt/ (last 3 codes). It works all fine. My problem is when I try to implement client in the browser using Paho. with this code:

// Create a client instance
var client = new Paho.MQTT.Client('127.0.0.1', 4883, "clientId-1");

// set callback handlers
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;

var options = {

     //connection attempt timeout in seconds
     timeout: 3,

     //Gets Called if the connection has successfully been established
     onSuccess: function () {
       console.log("onConnect");
       client.subscribe("testtopic/#");
     },

     //Gets Called if the connection could not be established
     onFailure: function (message) {
         console.log("Connection failed: " + message.errorMessage);
     }

 };

// connect the client
client.connect(options);

// called when the client connects
function onConnect() {
  console.log("onConnect");
  client.subscribe("testtopic/#");
}

// 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(message.payload);
}

I always get this message: "Connection failed: AMQJSC0001E Connect timed out."

When I change '127.0.0.1' to a online broker, it works. So, I'm guessing my problem is with allowing ports in my broker.

Does anyone know how to solve this problem?

DogG
  • 1
  • 1
  • Update your question to include the actual mosca broker code you are using. But at a first guess I would say that broker you have built is not listening for MQTT over WebSocket connections, only pure MQTT – hardillb Apr 04 '16 at 09:48
  • I guess you're right because all information I got says that I have to listen to MQTT over WebSocket connections. However, I didn't find information regarding how to do it. Thank you for your answer! – DogG Apr 05 '16 at 22:12

0 Answers0