Search code examples
androidsocket.ioandroid-volleyreactiveonline-game

best way to see if user is online in android application


I am making a game where to players play together in a game through internet,so i wanted to check to see if one of them left the game so i notify the other player .

currently i have written a code which runs every second on client side and sends a request to server but when ever it stops for 2 seconds then the player will be considered as "left the game" and the other player will get a response from server which tells it that the game stopped ,so as you can see there is a lot of requests from android client to server happening .

Is there anyway to do this better? someone told me socket programming may help but is it for this kind of works?i'm really used to using the volley library for android and sing it for requests


Solution

  • Have you thought of using socket.io instead of sending request from client side every time, socket.io would immediately know if somebody disconnects from the server as connection is persistent.