iOS Cloud: lock device disconnect photon connection

Paresh
edited August 2013 in Native
Hi,

I am facing this issue with iOS build on iPAD.
my game is connected with photon server, now I lock the device using hardware key, but the next moment when I unlock it, I get error "connection fail with error 1039"

I checked it & found that it's a getting called from network logic class inside :
[code2=cpp]void NetworkLogic::connectionErrorReturn(int errorCode) //call-back method
{CCLog("connection failed with error %d",errorCode);}[/code2]

further deep I found that this error is from photon cpp - StatusCode.h
static const int INTERNAL_RECEIVE_EXCEPTION = 1039; // Exception, if a server cannot be connected. Most likely, the server is not responding. Ask user to try again later.

but this is not behavior i am expecting, with this small interval of 2 seconds disconnecting user from server. Is it the way photon server work? or I can take over this issue & avoid this disconnection?

thanks.

Comments

  • Hi.

    If Photon immediately gets information from the OS, that the connection has broken, then it will immediately disconnect, too. It doesn't make much sense to wait several seconds and then trigger a timeout, if there already is the info that the connection isn't existing anymore. It's pretty difficult for Photon to identify the exact cause of the issue and usually it will be the better approach to just throw a connection error in such cases instead of pretending to be still connected while internally trying to reconnect the socket. Photon can't foresee that the user will unlock the device again, it won't even know, that the connection loss is due to a device lock and if it would know, then it would have to assume, that the device could stay locked for hours.
    If your app has enough information about the exact cause of the issue (for example if you get a callback from iOS, when the device gets unlocked), then you could of cause just tell Photon to connect again, otherwise bind the reconnect to a button, that the user could push when he wants to try a reconnect.
    You could also in case of a callback that the device gets locked, store some state information about the current game to recover on later, but keep in mind that you maybe won't be able anymore to send something out to the server, as the connection could already got lost at that time.
  • hi,

    I got your point, & agree with you. So I am reloading entire app & reinitiating photon network connection.

    but today I faced one more scenario like above, where battery low message pops up & after clicking on okay, network fail message triggered. which is completely unexpected behavior, this one is not user initiated event, so user not suppose to face this problem.

    Can you suggest me any way to overcome this?

    Thanks.
  • I have researched a bit on this and it seems like iOS automatically turns of Wifi to save battery life, when you lock the screen, and turns it back on, when you unlock it again. Probably its also turning off Wifi, when the battery is very low.

    Photon internally could just try to reconnect the socket in hope that there is a cellular connection, that is still alive. However I am not sure, if it is a good idea to switch from Wifi to cellular without the users explicit wish to do so. 3G "flatrates" usually are restricted in their max data volume to only a few GB a month and afterwards one only has 2G available. We may would without the users knowledge use up his last remaining MB that he has saved up for the rest of the month. Maybe the game gets unplayable with 3G in that region anyway or isn't playable with 2G at all. Maybe the user doesn't even have a 3G "flat" at all, but pays per kb and a few minutes of your game on 3G cost him a lot of dollars, while he doesn't even recognize, that he is now playing on a cellular connection.

    I think that the best may really be to tell the user, that he lost his network connection and ask him, if he wants to try to reconnect
  • Hi,
    I think that the best may really be to tell the user, that he lost his network connection and ask him, if he wants to try to reconnect

    Unfortunately I can't go with this for low batter message, our game based on turned based logic (it's not same but you can consider poker for reference). Now if player is inside room then he have invested chips for entry in that room & now if battery low message pops in then showing network fail & asking him to restart doesn't give good user experience. Asking for reconnect looks perfectly fine if he is locking the device or receiving call etc. I have seen few multiplayer game which don't ask for reconnect on battery low message. I just want to know if same is possible with photon or not?

    I hope you understand the user frustration if his game reconnect while he is having good cards & winning.

    Thanks,
    Paresh
  • I will discuss this internally.
  • when I can expect the feedback?
  • We may add some try to auto-reconnect logic at some time in the future, but I doubt that this will be in time for your release.
    You will have to handle this situation in your games networking logic at the moment.

    As you have mentioned that your game is to some degree comparable to Poker let me explain how for example Full Tilt Poker (Nr. 2 real money online Poker room, world wide with ten thousands of real money players, same owner as the Nr. 1 real money online poker room) handles connection losses for tourneys and sit n gos (I don't know out of my head how they handle it for cash game tables):
    When it is a players turn and he does not react in time, then the software checks if the client is still alive (pinging the server or reacting at other tables, etc.). If it is not, then the software automatically activates an extra disconnect time bank of 100 seconds for that client at all tables, at which he is playing, as soon, as its his turn at the respective table, to give the player the chance to reconnect without loosing money. If the player reconnects in that time, then he can continue to play as if he would never have been disconnected and the remaining time stays available for the case, that he gets disconnected again (you may want to choose adifferent amount of time for your game of course). In case that he does not reconnect in time, the hand will continue without him and the next time that it's his turn, the software will automatically fold his cards. The player may even restart his PC and login to the software again and all the tables at which he has been playing, when the disconnect has occurred, will pop up again and he can continue playing with his remaining chips (of course these chips now will be somewhat less then before, if he has been disconnected for some time, as he may had to pay the blinds multiple times over the time that he has been disconnected). They do it this way as a compromise between not taxing the other players patience too much with waiting for that player too long and not hurting that players bankroll too much by just throwing him out of the tables, at which he has been playing, completely and permanently, as the player may have been invested quite some money into the tourneys / SNGs at which he has been playing, when he has got disconnected (they host quite a lot of SNGs and tourneys in the nose bleed stake regions and a player may have several thousands of real money dollars at stake at once, when getting disconnected.
    You could use player or room properties, which contain the important values of a player like his amount of chips, to be able to reestablish his state in case he disconnects and reconnects right in the middle of a match.
    If a player gets disconnected for example due to the low battery message of iOS and then reconnects, just let him rejoin (all) the room(s) again (yes, being in multiple rooms at once is perfectly possible with Photon, but you would have to use a separate peer instance for each room), that he has been in when the disconnect has happened, and read out the properties to reestablish his game state. You would of course have to track on the client, in which rooms he has previously been in and you would have to let the rooms open, so that players can rejoin (but you may want to make it invisible, so that no new players will join it). In case that you want to even be able to rejoin after the device has been rebooted, you would either have to implement some custom server logic, so that the client can retrieve the info, in which rooms he is still in, from the server (only an option with Photon Server, not with Photon Cloud) or you could alternatively let the client store that info in a file on its local hard drive, which the app reads out on a restart (be prepared to handle the case that a match has been finished in the mean time so that that room has been closed and isn't available for rejoining anymore).
  • thanks for the information & guidance, we will discuss about your ideas.