How to keep connection longer time when app goes background.

Options
Shakthi Prasad G S
edited May 2014 in Native
Hi,
I am integrating game photon to my IOS game using OBJC api. Everything is working great. But when a user switches to background(on pressing home button) app gets disconnected from the server. I know the reasons (Because service request not is getting called) Is there a way to increase time so that it won't be disconnected when user comes back to the game within a small interval of time.
Thanks
-Shakthi


How to keep connection longer time when app goes background.

Comments

  • Kaiserludi
    Options
    Hi Shakthi.
    I am afraid there isn't a way to keep the connection, when another app takes focus, if your app isn't a voice over ip app or a music player or something like that, but if it is a game, as Apple ony allows certain kinds of apps to continue runnin in background. The rest of the appa just stay in memory as long as enough memory is available for them, but don't continue running. As no code gets executed in that state, there isn't any way for Photon to keep the connection alive. I recommend that you save your state in the callback, in which iOS tells you, that it will switch your app to suspended state and to reconnect and join the room again, in which you have been before, when your app gets active again.
    You can set the timeout of your Client to a higher value to prevent a client side disconnect, but then you will just get disconnected by hitting the serverside timeout. If you use Photon server and not Photon Cloud, then you can also increase the serverside timeout, but even that would probably not help much in this situation as the socket used by Photon will simply die when your app gets suspended.
  • If I connected back to while game returns to foreground, Is it possible to retain the game session, I mean remaining joined to the active room.
  • Kaiserludi
    Options
    We are working on a rejoin feature for the next bigger update (probably Photon 3.6 or Photon 4.0), but for now I am afraid that you will have to handle differentiation between a new player and a returning one yourself.
  • tasadar
    Options
    hi, i have a similar issue that i get 1041 timeout issues when the game map is loading. my game is on pc, loading times can get long and i find myself disconnected when the game loads. any idea to prevent this, thanks.
  • Kaiserludi
    Options
    Hi tasadar.

    I assume the answer to the question which map you need to load depends on the room that the player is joining, so you can't load it before connecting to Photon, because you will have to create/join a room, before you know which map to load? Otherwise the simplest solution would be to just first load that map and then connect.

    You could load your map in a separate thread, so that your main thread stays responsive (In general it's a bad idea to block the main thread for several seconds while loading, as during that time it could not only not keep the connection alive, but it also could not update any graphical output, not react to input, etc. (if you can still do that stuff, so that your map load isn't actually blocking, then just also make calls to service() the same way)).
  • tasadar
    Options
    thank you, we tried to make time sliced loading and managed to keep calling service() for a couple of times per second.
    much easier than multithreading and does the work for now :D