Paho Rabitmqq连接失败 [英] Paho Rabitmqq connection getting failed

查看:268
本文介绍了Paho Rabitmqq连接失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的paho客户代码

// Create a client instance
client = new Paho.MQTT.Client('127.0.0.1', 1883, "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);
}  

Rabbitmq服务器上,所有内容都是默认值.当我运行此代码时,我得到WebSocket connection to 'ws://127.0.0.1:1883/mqtt' failed: Connection closed before receiving a handshake response

On Rabbitmq server everything is default seetings. When i run this code i get WebSocket connection to 'ws://127.0.0.1:1883/mqtt' failed: Connection closed before receiving a handshake response

我想念什么?

推荐答案

问题尚不清楚,但我认为您正在Web浏览器中运行以上代码.

It's not clear in the question but I assume you are running the code above in a web browser.

这将通过Websockets建立MQTT连接(如错误所示).这与TCP连接上的本机MQTT不同.

This will be making a MQTT connection over Websockets (as shown in the error). This is different from a native MQTT over TCP connection.

默认的纯MQTT端口,如果Websocket支持1883,则可能在其他端口上.

The default pure MQTT port if 1883, Websocket support is likely to be on a different port.

您将需要配置RabbitMQ以通过Websocket以及纯MQTT接受MQTT,这 pull 请求RabbitMQ接缝以谈论添加此功能.它提到此功能仅在3.6.x版中添加,并且文档仍很出色(截至2016年2月9日)

You will need to configure RabbitMQ to accept MQTT over Websockets as well as pure MQTT, this pull request for RabbitMQ seams to talk about adding this capability. It mentions that this capability was only added in version 3.6.x and that the documentaion is still outstanding (as of 9th Feb 2016)

这篇关于Paho Rabitmqq连接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆