1

I am working on a application using Socket.IO implemented with 'com.github.nkzawa:socket.io-client:0.5.1'. All works fine but issue is when phone goes to the idle mode or sleep mode, socket is disconnected from server. guide me how i make socket alive while phone goes to sleep.

i tried already using wakelock and use Foreground service to keep my sockt connection alive but not solve the issue.

I want my socket always alive while phone is in sleep mode or not.

Jay Thakkar
  • 1,392
  • 10
  • 19
  • Check this answer https://stackoverflow.com/questions/36301291/cannot-keep-socket-connection-when-screen-off-in-android – Anas Mehar Aug 31 '19 at 07:40
  • i did that but issue remains same.socket disconnects after some time when the screen goes off. – Syed Mustafeez Aug 31 '19 at 12:59
  • You can't keep the socket alive forever on a battery-powered mobile device. Doing so would kill the phone's battery so phone browser makers don't allow it as it would only take one poorly behaved app to kill your battery. If you build a native app, you can use the platform's "push" APIs to be able to push data to your app at any time. – jfriend00 Aug 31 '19 at 16:58
  • I want to built a chat app so i want my user to stay login until he want to decide to logout himself. so i want my socket to stay alive on that period of time. is there any possible way to do that? – Syed Mustafeez Sep 02 '19 at 08:14
  • I have had similar issue in my chat app,only when mobile user use wi fi connection is alive as user wants. – Goran_Ilic_Ilke Feb 02 '22 at 15:48

0 Answers0