Background disconnects workaround Photon-iOS_v3-0-3-4_SDK

edited November 2012 in Native
Minimize game to tray when playing (Update stops)
Expand app back, update returns.

And on execution of [m_pLitePeer service: true]; calls - (void) onStatusChanged:(int)statusCode с statusCode==1039 (SC_INTERNAL_RECEIVE_EXCEPTION) and then Crash
#2 0x0011b59c in ExitGames::PhotonConnect::sendBuffer(char*, int) at /Developer/egn/neutron-windows/branches/v3.0.3.x/Photon-c/src/PhotonConnect.cpp:324
#3 0x0011ba9a in ExitGames::PhotonConnect::sendPackage(unsigned char*, int) ()
#4 0x00114d68 in ExitGames::EnetPeer::sendOutgoingCommands() ()
#5 0x001194b6 in ExitGames::PeerBase::service(bool) ()
#6 0x001130e2 in PhotonPeer_service at /Developer/egn/neutron-windows/branches/v3.0.3.x/Photon-c/src/CPhotonPeer.cpp:273
#7 0x001090b8 in -[PhotonPeer service(inlove) at /Developer/egn/neutron-windows/branches/v3.0.3.x/Photon-objc/src/PhotonPeer.m:563
#8 0x00065e38 in -[CPhotonLib Run] at /Users/kolyan/Documents/AMT Games/Projects/General/Prison Fun/Sources/PrisonFun/PrisonFun/Sources/PhotonDemo.m:787


  • The problem is, that when you minimize an app in iOS, that doesn't mean, that it is continueing to run like on a Desktop OS. Its stays in memory, but doesn't do anything. However when the app holds an open socket-connection, then this connection will time out after a while of the app being minimized. When the app comes to foreground and calls PhotonPeer::service() again, the Photon client then throws an error, as its socket isn't working anymore.
    As a workaround you could call PhotonPeer::disconnect(), when your app enters background and call PhotonPeer::connect() again, when it reenters foreground.
  • There's another problem with minimizing the game. Here's how you can reproduce the problem:

    1. Take the sample demo_iPhone_realtime_objc
    2. In the Info.plist remove flag (Application does not run in background).
    3. Run the app
    4. Press power button on iPhone/iPod to lock the devide.
    5. Unminimize app from the background
    6. Crash

    And you get this error: onStatusChanged: с statusCode==1039 (SC_INTERNAL_RECEIVE_EXCEPTION)
    If instead the power button you press home button there won't be crash.

    Can you please help with this?
  • Photon-iOS_v3-0-3-5_SDK fixed this issue!

    But another problem occured. Why, when right after you call the method - (void) onStatusChanged: (int) statusCode with SC_INTERNAL_RECEIVE_EXCEPTION (1039) you can't call the same method with SC_DISCONNECT, as you can in C++ SDK?

    You can reproduce this issue this way:
    Take demo_iPhone_realtime_objc, and in Info.plist remove "Application does not run in background".
    Start the game, press power and then instantly unminimize the game. You will have onStatusChanged with statusCode == SC_INTERNAL_RECEIVE_EXCEPTION looped.
  • Both, the objective C and the C++ demo, don't get SC_DISCONNECT in case of SC_INTERNAL_RECEIVE_EXCEPTION.
    However this is intended behavior: SC_DISCONNECT is indicating, that a prior call to PhotonPeer::disconnect() has been successfull.
    For example you also don't get SC_DISCONNECT, but other status codes, if the server disconnects the client for some reason or if the disconnect is triggered by a timeout.
    That is because in errorcase you most likely want your game to behave differently than after a successfull normal disconnect.

    You can simply add the lines
    [m_pLitePeer disconnect];
    to the switchcase in demo_iPhone_realtime_objc or according C++ code to demo_iPhone_realtime to let it disconnect in case of that error.
    You will then get SC_DISCONNECT shortly afterwards and can trigger your reconnection logic there.
  • where can i download Photon-iOS_v3-0-3-5_SDK ?

    i use Photon-iOS_v3-0-4-0_SDK but i get error with follow:

    in ConfirmAllowedKey.h row 21:

    error:Implicit instantiation of undefined template 'ExitGames::Common::Helpers::CompileTimeAssertTrue<false>;

    i used Xcode 4.4.1,photon-cpp lib,i use Photon-iOS_v3-0-3-4_SDK is right
  • has been removed from the downloadaraea, when has been released some time ago.

    I could sent you the Client (same API like, but with several bug fixes, that have been introduced between theses versions), but I think, that it makes more sense to not go back from to a 3.0.3.x version because future versions will base on the most recent release, not on an older one, so that it will be less work to update from to or to than from a 3.0.3.x version. has also introduced a lot of improvements, new features, bug fixes, and so on, which you won't be able to use, if you go back to a previous release.

    Your compilation error looks like you have not yet adjusted your game to the simplifications in the API, that have been introduced by version

    Here is the according entry from release_history-common-cpp.txt inside the SDK:
    - changed: reworked the API of class Hashtable for simpler usage:
    - Note: you will have to adjust your calls to this API like in the following example, when upgrading to the new version:
    - old way to add an entry to a Hashtable-instance:
    hash.put(ExitGames::Common::KeyObject<ExitGames::Common::JString>(ExitGames::Common::JString(L"key")), ExitGames::Common::ValueObject<int>(1));
    - new way:
    hash.put(L"key", 1);
    If that does not help, then please post the lines of code, which cause the error (ConfirmAllowedKey.h line21 is just the line, that throws the error, not the one, that actually causes it. You can find further information, when you are expanding the error message in Xcode. The line in your code, that has to be adjusted to fix the error, can probably be found by clicking on the second line from the bottom of the error message.)

    However if you don't have the time to update your code to the API-changes from, please tell me so. I would dig out the iOS client SDK for you from our archives then.
  • Thanks a lot,i solved my problem with your help~
Sign In or Register to comment.