1***@qq.com
1***@qq.com
  • 发布:2024-08-08 16:20
  • 更新:2024-08-08 16:20
  • 阅读:284

mqtt版本是mqtt.js4.1.0,用阿里云的mqtt,微信小程序之前能连,最近突然连不上,一直重连,h5和mqtt.fx工具都能连接

分类:uni-app

async connectMqtt() {
return new Promise((resolve, reject) => {
const options = {
connectTimeout: 5000,
clientId: this.mqttInfo.clientAccessInfo.clientId,
address: this.mqttInfo.clientAccessInfo.endPoint, // 输入的连接地址
port: 443, // 输入的端口号
username: this.mqttInfo.clientAccessInfo.username, // 输入的用户名
password: this.mqttInfo.clientAccessInfo.password, // 输入的密码
resubscribe: true,
keepalive: 20
}
this.client = mqtt.connect('wxs://' + options.address, options) // 连接方法

    this.client.on('connect', (res: any) => {  
      console.warn('连接成功')  
      resolve(res)  
    })  
    this.client.on('reconnect', (error: any) => {  
      console.warn('正在重连:', error)  
    })  
    this.client.on('close', (error: any) => {  
      console.warn('断开连接', error)  
    })  
    this.client.on('error', async (error: any) => {  
      console.warn('连接失败:', error)  
      reject()  
    })  
  })  
},  
2024-08-08 16:20 负责人:无 分享
已邀请:

要回复问题请先登录注册