Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

无法连接,出现AMQJS0007E #25

Open
chentianci123 opened this issue Nov 12, 2019 · 5 comments
Open

无法连接,出现AMQJS0007E #25

chentianci123 opened this issue Nov 12, 2019 · 5 comments

Comments

@chentianci123
Copy link

代码:
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
Copy link
Author

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

@chentianci123
Copy link
Author

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

@huzhengxi
Copy link

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

解决了吗 老铁

@inkCrazy
Copy link

inkCrazy commented Mar 5, 2021

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants