Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

239
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!