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

amtgames
edited November 2012 in Native
Photon-iOS_v3-0-3-4_SDK
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

Comments

  • 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
    case SC_INTERNAL_RECEIVE_EXCEPTION:
    [m_pLitePeer disconnect];
    break;
    
    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:

    COMPILE_TIME_ASSERT_TRUE_MSG(N-N, ERROR_UNSUPPORTED_KEY_TYPE);
    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
  • 3.0.3.5 has been removed from the downloadaraea, when 3.0.3.6 has been released some time ago.

    I could sent you the 3.0.3.8 Client (same API like 3.0.3.5, 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 3.0.4.0 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 3.0.4.0 to 3.0.4.1 or to 3.0.5.0 than from a 3.0.3.x version. 3.0.4.0 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 3.0.4.0.

    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 3.0.4.0, please tell me so. I would dig out the iOS 3.0.3.8 client SDK for you from our archives then.
  • Thanks a lot,i solved my problem with your help~