Introvertuous / react-native-mqtt

Mqtt client for react native.
MIT License
158 stars 30 forks source link

无法连接,出现AMQJS0007E #25

Open chentianci123 opened 4 years ago

chentianci123 commented 4 years ago

代码: import { AsyncStorage }from'react-native'; import init from 'react_native_mqtt'; init({ size: 10000, storageBackend: AsyncStorage, defaultExpires: 1000 3600 24, enableCache: true, reconnect: true, sync: {} }); //第一步:创建 // 地址,端口,路径(这么写就行了),connectId(随便写) :地址和端口,都是后台给,或者你自己弄个mqtt的服务 //完整路径为:mqtt://192.168.22.149:1883 let client = new Paho.MQTT.Client('192.168.22.149',1883,'/mqtt','aaa')

    //第二步:连接,暂时有一个参数,2个方法:成功,失败
    client.connect({
        useSSL: false,
        onSuccess: onConnect,
        onFailure:(e)=>{ console.log('失败'); console.log(e); }
    });
    // 成功后需要发送主题 ,就是一个接口的路径类似
    function onConnect(){
        console.log('成功');
        client.subscribe('/fangtao');
    }
    //第三步:断掉
    // client.onConnectionLost = onConnectionLost;

    // function onConnectionLost (responseObject) {
    //     if (responseObject.errorCode !== 0) {
    //     console.log('onConnectionLost:' + responseObject.errorMessage);
    //     }
    // }

    // 第四步:接收消息
    client.onMessageArrived = onMessageArrived;

    function onMessageArrived (message) {
        console.log('消息:' + message.payloadString);
    }

版本: "react": "16.9.0", "react-native": "0.61.1", "react_native_mqtt": "^1.3.1"

报错信息: 失败 {"errorCode":7,"errorMessage":"AMQJS0007E Socket error:undefined.","invocationContext":undefined}

chentianci123 commented 4 years ago

希望可以帮我解决这个问题,谢谢

chentianci123 commented 4 years ago

现在又遇到一个问题,Error:AMQJS0013E Invalid argument mqtt://192.168.22.149:1883 for host

huzhengxi commented 3 years ago

现在又遇到一个问题,Error:AMQJS0013E Invalid argument mqtt://192.168.22.149:1883 for host

解决了吗 老铁

inkCrazy commented 3 years ago
let username = "xxx";
let passWord = "xxx";
let hostname = "ws://xxx.xxx.2.150/ws";  //替换成的你百度实例地址
let port = "15675";    //使用WSS协议的接口地址

Fri, 05 Mar 2021 05:59:42 GMT - ERROR - Failed to connect. [Error Message: AMQJS0007E Socket error:undefined.] 有人遇到这个问题吗?

billmiranda101 commented 2 years ago

This Library uses web-sockets. Your Port should be of the web-socket, not TCP port. E.g: https://developpaper.com/using-websocket-to-connect-to-mqtt-server/

In the link above you see that for this broker: Broker: broker.emqx.io

//..................................................

TCP Port: 1883 //..................................................

Websocket Port: 8083

I changed to this web-socket port . It fixed the error.