1

I have a simple application written in react native that uses a nodejs server connection with socket.io. My problem is that when the phone screen is locked the socket disconnects from the server. I need the always connected connection.

//server 
const app = express();
const server = require('http').Server(app);
const io     = require('socket.io')(server,{
  pingInterval: 20000,
  pingTimeout: 10000,
});

//client mobile 
const io = socket("http://192.168.0.20:3003");
  • 1
    Can you show [some code](https://stackoverflow.com/help/minimal-reproducible-example? – Rojo Oct 29 '19 at 18:55
  • @Rojo I edited the question for clarity. – Josias Pereira Oct 29 '19 at 20:12
  • Sounds like the OS controls that. Here's [one possible workaround](https://stackoverflow.com/questions/35458549/how-to-run-socket-io-in-the-background-on-ios-in-a-react-native-app). – Phix Oct 29 '19 at 20:21

1 Answers1

0

It is difficult to continue socket.io connection on the lock screen. (This is possible if you set a manifest that uses VoIP in the app) I encountered the same problem and took action.

The countermeasure method was released to npm as "syncsocketio". https://www.npmjs.com/package/syncsocketio

"syncsocketio" wraps socket.io. "syncsocketio" was created with Typescript, but it can also be used with javascript. Note that you need to use "syncsocketio" on both the server and client. The npm page is in Japanese, but using the sample code is very easy to use.

Github also contains server and client test code, so check it out. https://github.com/codianz/syncsocketio

I will be happy if it helps.