Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

231
Vistas
React Native app connected to AWS Python server via WebSockets disconnects, and won't reconnect

I have a react native app that uses an AWS server, written in Python, that is connected via WebSockets.

When users navigate away from the app for a time greater than ~30 seconds, they disconnect from the server and the WebSocket closes.

This prevents our users from being able to do anything within the app, as the WebSocket closing prevents the front end of the app from communicating to the server.

I've tried to perform a "CPR" on the WebSocket so that when it disconnects, it reconnects to the server.

Below is my code on the front end that attempts to reconnect the app:

global.number_of_attempts = 20

function restore_attempts(){
  if (client_instance.websocket.is_connected){
   global.number_of_attempts = 20 // reset on success
  console.log(number_of_attempts, 'number of attempts is here')
 }
}

function websocketCPR() {
  client_instance = new UserClient(DEFAULT_SETTINGS)
  client_instance.connect() //this allows it to connect to ws
  setTimeout(restore_attempts, 10000) // reset on success
  
  client_instance.websocket.onclose = function(evt) {
    console.log("THE WEBSOCKET IS NOW _CLOSED__")
      global.number_of_attempts = global.number_of_attempts - 1
    console.log(global.number_of_attempts, 'it is attempted')

    if (global.number_of_attempts > 0){
      client_instance = null        
      setTimeout(websocketCPR, 500)
    }
  }
}

client_instance.websocket.onclose = function(evt) {
  console.log("THE WEBSOCKET IS NOW _CLOSED__")
      global.number_of_attempts = global.number_of_attempts - 1
  console.log(global.number_of_attempts, 'it is attempted')

    if (global.number_of_attempts > 0){
      client_instance = null
      setTimeout(websocketCPR, 500)
    }
} 
about 4 years ago · Juan Pablo Isaza
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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda