no internet-connection causing crash?

Options
With PUN 1.18 if I turn off my wi-fi so there's not internet-connection unity freezes when it calls PhotonNetwork.ConnectUsingSettings(""). Same thing happens on the phone and something about a socketException comes up in Xcode.

Any ideas how to work around this? Wrap it in some check for internet-connection first or does PUN already do that?

Comments

  • Mishaps
    Options
    I made a function to check the connection first. It uses unity's built-in WWW thing to check if it can find the cloud URL before giving the okay to go ahead and call PhotonNetwork.ConnectUsingSettings("").

    Seems to work, does anyone see anything wrong doing it this way?

    [code2=javascript]private var www : WWW;
    private var hasNetworkConnection : boolean;
    function checkConnection()
    {
    www = new WWW("app-us.exitgamescloud.com");
    yield www;

    if(www.error != null)
    {
    hasNetworkConnection = false;
    Debug.Log("app-us.exitgamescloud.com could not be found");
    } else {
    hasNetworkConnection = true;
    Debug.Log("app-us.exitgamescloud.com was found");
    }

    }[/code2]
  • Tobias
    Options
    I will have to check this (might take a while, cause I have to assign time to it).
    So, you get this issue in iOS exports?
  • Mishaps
    Options
    Thanks Tobias that would be great if you get the chance. My solution / work-around seems to be working now, I just assumed the photon would send me a fail event if the connect thing failed instead of crashing the game.

    Yep iOS, BTW for anyone else with the same problem I found the WWW thing didn't work on the iPhone so I did another check for "if (Application.internetReachability == NetworkReachability.NotReachable)".
  • Tobias
    Options
    We checked PUN 1.19 in iOS, Windows, Android and MacOs but couldn't reproduce this with a simple connect script. No matter if connection wasn't available at all or cut off during start.
    Maybe the issue is now gone or we need some help reproducing it.
  • Mishaps
    Options
    sounds promising :) I'll try it out and let you know.
  • Tobias
    Options
    Cool.
    If you still run into the issue, you could also try our demo apps please. Maybe our workflow is just a bit different compared to yours.
    If possible, please provide a test case, so we can reproduce the issue.
  • Mishaps
    Options
    repro: empty project, switch to iOS, import photon 1.19 from the unity asset, add a cloud ID and select US server. Turn off wifi, open scene "DemoHub-Scene", select any of the demo scenes and it crashes with two errors (see screenshot attached). "Dns.GetHostEntry(app-us.exitgamescloud.com) failed: System.Net.Sockets.SocketException: No such host is known" and "Connect() failed: System.ArgumentNullException: Argument cannot be null."

  • Mishaps
    Options
    Like in previous posts I made a connectivity checker myself that seems to be doing the job. I suppose I was expecting some kind of callback like OnPhotonRandomJoinFailed() when I try to connect with no web access. Like OnConnectUsingSettingsFailed() or something 8-) .
  • Tobias
    Options
    Update:

    As far as I can see, you only have to implement OnFailedToConnectToPhoton(DisconnectCause cause).
    When you fail to connect (no matter if DNS is impossible or URL is not existing), you get a OnFailedToConnectToPhoton() call.

    I checked with bad hostnames and bad ports. The only thing not covered should be a ":" in the host name, which leads to an un-parsable port number which just plain fails to cause some callback. Worse: The exception thrown is passed through all levels back to the caller of Connect().
    This is going to change but I don't want to make this change right now, cause it has to be tested on several platforms, which costs time. I got a PUN update almost ready, so this port issue has to wait until next release.

    Hope this helps.
  • Mishaps
    Options
    Cheers Tobias thanks for looking into this. I tried adding OnFailedToConnectToPhoton(DisconnectCause cause) to my script. It was definitely called but I still experienced a crash when wifi is off. Attached is a screenshot of the console when it crashed in my repro.

    EDIT: repro is same as prev post but using DemoBoxes-Scene and added OnFailedToConnectToPhoton(DisconnectCause cause){...} to ConnectAndJoinRandom.cs

  • Tobias
    Options
    It's an exception, yes, but it's being handled. If it was unhandled, the code following it wouldn't be called. The log looks mean as we print it as error but actually, you can ignore as you understand why it's called and now use the callback.
  • Mishaps
    Options
    Thanks Tobias you are absolutely right. I've also run it on the device and Xcode says a nullException when photon connects with wifi off but it doesn't cause the game to crash. In-editor it is still causing a crash. If it's not a problem then why is the editor crashing? Can I make a kinda newbie suggestion to change this from a error log to a warning log? This way the editor would behave more like the device so testing is easier? :)
  • Tobias
    Options
    Good to read it's working on device.
    The error log in the editor is actually good (imho), cause it points your attention to it. We could turn this log category into a warning though. That's true :)

    Aside from that: It does not crash the editor. It's a log ;)