WebSocket keeps disconnecting, hard to debug

I'm using WebSocket in React Native, but on Android the connection keeps dropping periodically. Has anyone experienced something similar? Does anyone know a fix?

by 취준생김씨313

3 answers

Yeah, I've been through it too. Phone sleep mode is probably the culprit.

by 월급루팡827 · ▲0

It might be due to Android Doze mode. It's a common problem that WebSockets die when the screen turns off, so try using a wakelock or foreground service to keep it alive. If it happens periodically, also check network switching.

by 스타트업러600 · ▲0

Well, if it's disconnecting periodically, it could be a server or code issue. I'd say the first thing to do is check whether the reconnection logic is properly set up lol.

by 데이터덕후611 · ▲0