• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

253
Vistas
Connection failed - trying to connect to the mosquitto broker using React native

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, }

import init from 'react_native_mqtt'
import AsyncStorage from '@react-native-async-storage/async-storage'

 init({
  size: 10000,
  storageBackend: AsyncStorage,
  defaultExpires: 1000 * 3600 * 24,
  enableCache: true,
  reconnect: true,
  sync : {
  }
});
 
   constructor(){
    super();
    this.onConnect = this.onConnect.bind(this)
    const client = new Paho.MQTT.Client('52.11.11.11', 1883, "clientId-" + parseInt(Math.random() * 100, 10));
    client.connect({ 
      onSuccess: this.onConnect,
      userName: "user",
      password: "pass",
      onFailure: (e) => {console.log("here is the error" , e); }

    });

    this.state = {
      message: [''],
      client,
      messageToSend:'',
      isConnected: false,
    };

  }

  onConnect = () => {
    const { client } = this.state;
    console.log("Connected!!!!");
    this.setState({isConnected: true, error: ''})
  };
almost 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

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

almost 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda