Rapsssito / react-native-tcp-socket

React Native TCP socket API for Android, iOS & macOS with SSL/TLS support.
MIT License
315 stars 80 forks source link

iOS: Server not responding after getting to background and back. No error event triggered #68

Closed kelcon closed 4 years ago

kelcon commented 4 years ago

Description

Server not responding after getting to background and back No error event triggered

Steps to reproduce

I have basic server configuration (simple http server). It works perfect while on foreground. If go background, it will stop responding after several seconds. It will not go back nor emit error or close event.

Options:

{
  port: 3032, 
  host: '0.0.0.0',   
  reuseAddress: true,  
}

Current behavior

As described above.

Expected behavior

I assume that error should be triggered as a clou to restart listening.

Screenshots If applicable, add screenshots to help explain your problem.

Relevant information

OS 13.3
react-native 0.62.2
react-native-tcp-socket 4.2.0
Rapsssito commented 4 years ago

@kelcon, sorry you have that issue. Sadly, iOS closes all TCP connections after a short period of time after the app has been sent to the background.

However, you can use a background service React Native library to keep your app running in the background with all sockets open. I created react-native-background-actions, but there are a lot of similar libraries.

kelcon commented 4 years ago

Thank you. I will check it. I have discovered other approach in the mean time - to listen for an app state change and respawn server after "active" state event.