[Solved] Unity Exception when Server is offline

So, a small thing I have been wrestling with are the following two cases:

Case 1)
The server is available, but the Photon Server Application is not running (no response on the specified port)

Connecting:
PhotonNetwork.ConnectUsingSettings(gameVersion.Value);

And with the server offline (or simply by entering a wrong address/ip) I get the following error.
The exception translates to "An existing connection was closed by the remote host."
Receive issue. State: Connected Exception: System.Net.Sockets.SocketException: Eine vorhandene Verbindung wurde vom Remotehost geschlossen.

  at System.Net.Sockets.Socket.Receive (System.Byte[] buffer) [0x00000] in <filename unknown>:0 
  at ExitGames.Client.Photon.SocketUdp.ReceiveLoop () [0x00000] in <filename unknown>:0 
UnityEngine.Debug:LogError(Object)
PhotonHandler:DebugReturn(DebugLevel, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:153)
NetworkingPeer:DebugReturn(DebugLevel, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:937)
ExitGames.Client.Photon.<>c__DisplayClass2:<EnqueueDebugReturn>b__0()
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:76)

That is where the Unity Editor pauses due to the exception being raised. If I unpause the game, my Playmaker ConnectionManager receives the "Photon / Failed to Connect to Photon" event which means that it gets raised correctly. So why is the exception raised when there is an event handling this case? I really don't want to mess with your source to prevent this exception from happening, but I can't be the first to encounter this situation. Am I doing something wrong?

Case 2)
The server is unavailable, because it is completely "offline" (IP/Address doesn't exist).

Connecting:
PhotonNetwork.ConnectUsingSettings(gameVersion.Value);

No event seems to be raised at all. I fire the connect and it the game just connects endlessly.

I hope someone can help me and I wish you a great weekend.

Patrick

Comments

  • 1) In the player, I think "Error Pause" is an option in the Console. Deselect it to stop the pause.
    The exception is logged for debugging purposes. It's fetched and handled, as you already noticed. The callback is for your code to be able to react to the issue.
    Is the logging an issue for you? It should only happen on your machine. Only then Windows is clever and raises this exception. On remote hosts, you will have a timeout.

    2) Connect is in fact defined as "bool Connect*()". If the Address is unreadable, the result will be false and tells you the client doesn't even attempt to reach the server.
    This is a relatively rare case when you begin or change servers a lot. It should not be relevant in a release (where hopefully the address is OK).
  • Kerozard
    edited August 2014
    Thank you for your reply.

    1) I think it is only a matter of development style. I see every thrown exception as something that I should fix and I try to keep my Editor console in Unity3d as clean as possible. I am already wrestling with a couple of other plugins throwing warnings about obsolete methods etc. On the one hand the exception is great if I forget to start the server in the morning, on the other hand maybe a warning for this case would suffice. It is debatable, so I won't push the issue.

    2) I didn't check for a return value. Of course. Thank you very much. My mind was in asynchronous mode :-)
  • 1) Hm, good point about plugins spamming your console. I think I can hide the log for this exception in a higher logging-level which does not show up in all cases. Your code can react to "no server" without this extra logging.

    2) I rarely check this return in our demos myself, so it's easy to overlook. Sorry you had to waste some time on it.