2916关注10430浏览
appservice?t=1533630357896:1032 WebSocket connection to 'wss://36.41.188.53/mqtt' failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT
我在微信小程序中是用mqtt协议,通过nginx代理监听443端口,在本地测试通过,但是在连接服务器是报上述异常,可以ping通ip,telnet也可以连接服务器也正常,MQ使用的是emqttd,恳请各位大佬指点。
// pages/connect/connect.js
var app = getApp();
var MQTT = require("../../utils/paho-mqtt.js");
Page({
/**
* 页面的初始数据
*/
data: {
server_addr: '36.41.188.53',
user_name: "test",
user_psw: ['1','2','3','4','5','6','7','8','9'],
error_message: '',
switch_checked: false,
btn_loading: false
},
server_addr_input: function(e) {
//console.log(e);
this.setData({
server_addr: e.detail.value
});
},
user_name_input: function(e) {
//console.log(e);
this.setData({
user_name: e.detail.value
});
},
user_psw_input: function(e) {
//console.log(e);
this.setData({
user_psw: e.detail.value
});
},
switch_change: function(e) {
//console.log(e);
this.setData({
switch_checked: e.detail.value
});
},
btn_connect: function() {
//查看输入是否为空,设置错误信息
if (this.data.server_addr == '' || this.data.server_addr == null) {
this.setData({
error_message: "server address can not be empty!"
});
return;
}
if (this.data.switch_checked) {
if (this.data.user_name == null || this.data.user_name == '') {
this.setData({
error_message: "user name can not be empty!"
});
return;
}
if (this.data.user_psw == null || this.data.user_psw == '') {
this.setData({
error_message: "user password can not be empty!"
});
return;
}
}
//reset error message
if (this.data.error_message) {
this.setData({
error_message: ''
});
}
//在按钮上显示加载标志
this.setData({
btn_loading: true
});
var client = new MQTT.Client("ws://" + this.data.server_addr + "/mqtt", "mqttjs" + Math.random().toString(36).substr(2));
var that = this;
//connect to MQTT broker
var connectOptions = {
timeout: 10,
useSSL: true,
cleanSession: true,
keepAliveInterval: 30,
reconnect: true,
userName: "test",
password: "123456789",
onSuccess
-
至过去的我
2044人对此回答表示赞同
我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多> -
Robert
20人对此回答表示赞同
主,请问问题解决了吗,我也是同样的问题。
展开200回复分享发布于 6年前评论(0)
收起评论