I tried to bind MQTT with the react native. When trying to connect to the broker, when I run my code, After a few minutes I get the following error:
here is the error Object { “errorCode”: 7, “errorMessage”: “AMQJS0007E Socket error:undefined.”, “invocationContext”: undefined, }
JavaScript
x
40
40
1
import init from 'react_native_mqtt'
2
import AsyncStorage from '@react-native-async-storage/async-storage'
3
4
init({
5
size: 10000,
6
storageBackend: AsyncStorage,
7
defaultExpires: 1000 * 3600 * 24,
8
enableCache: true,
9
reconnect: true,
10
sync : {
11
}
12
});
13
14
constructor(){
15
super();
16
this.onConnect = this.onConnect.bind(this)
17
const client = new Paho.MQTT.Client('52.11.11.11', 1883, "clientId-" + parseInt(Math.random() * 100, 10));
18
client.connect({
19
onSuccess: this.onConnect,
20
userName: "user",
21
password: "pass",
22
onFailure: (e) => {console.log("here is the error" , e); }
23
24
});
25
26
this.state = {
27
message: [''],
28
client,
29
messageToSend:'',
30
isConnected: false,
31
};
32
33
}
34
35
onConnect = () => {
36
const { client } = this.state;
37
console.log("Connected!!!!");
38
this.setState({isConnected: true, error: ''})
39
};
40
Advertisement
Answer
We solved this by edit the mosquitto config file to either add a new listener port 8883 and to use the websocket protocol for that port https://stackoverflow.com/a/32309525/12166187