OnFailedToConnectToPhoton is not called; SocketException?!

OnFailedToConnectToPhoton event is not being called. Instead I am seeing this exception in the logfile. This seems bad- it will mean my game will crash or hang in real world situation, right? I am testing this from a coffee shop w/ crappy network. So I assume it's http only firewall or something like that. How can I recover from this Exception and why isn't OnFailedToConnectToPhoton being called on my PhotonView?

System.Net.Sockets.SocketException: Connection refused
at System.Net.Sockets.Socket.Send (System.Byte[] buf, Int32 offset, Int32 size, SocketFlags flags) [0x00000] in <filename unknown>:0
at ExitGames.Client.Photon.NConnect.SendUdpPackage (System.Byte[] data, Int32 length) [0x00000] in <filename unknown>:0
at ExitGames.Client.Photon.EnetPeer.sendData (System.Byte[] data) [0x00000] in <filename unknown>:0
UnityEngine.Debug:LogError(Object)
PhotonHandler:DebugReturn(DebugLevel, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:125)
NetworkingPeer:DebugReturn(DebugLevel, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:680)
ExitGames.Client.Photon.EnetPeer:sendData(Byte[])
ExitGames.Client.Photon.EnetPeer:SendOutgoingCommands()
ExitGames.Client.Photon.PhotonPeer:SendOutgoingCommands()
PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:101)

Comments

  • Even if the console logs something right away, there is a retry mechanism for anything UDP related. The call of OnFailedToConnectToPhoton might take up to 30 seconds despite this.

    Please verify you gave it time to timeout.
    Then we could try to reproduce it.
  • Thank you Tobias! I will try that.
  • A related question:
    It looks like OnDisconnected is being called immediately after OnFailedToConnect. That's unexpected and will make recovering from real initial connection problems difficult or impossible. I'm probably just misunderstanding?

    OnFailedToConnectToPhoton!
    UnityEngine.Debug:Internal_Log(Int32, String, Object)
    UnityEngine.Debug:LogError(Object)
    PhotonNetMgr:OnFailedToConnectToPhoton()
    UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
    NetworkingPeer:SendMonoMessage(PhotonNetworkingMessage, Object[])
    NetworkingPeer:OnStatusChanged(StatusCode)
    ExitGames.Client.Photon.NConnect:StartConnection()
    ExitGames.Client.Photon.EnetPeer:Connect(String, String, Byte)
    ExitGames.Client.Photon.PhotonPeer:Connect(String, String, Byte)
    NetworkingPeer:Connect(String, String, Byte)
    PhotonNetwork:Connect(String, Int32, String, String)
    PhotonNetwork:ConnectUsingSettings(String)
    PhotonNetMgr:Boot()
    GameManager:Start()

    (Filename: /Applications/buildAgent/work/b0bcff80449a48aa/Runtime/ExportGenerated/MacStandalonePlayer/UnityEngineDebug.cpp Line: 43)

    OnDisconnectedFromPhoton!
    UnityEngine.Debug:Internal_Log(Int32, String, Object)
    UnityEngine.Debug:LogWarning(Object)
    PhotonNetMgr:OnDisconnectedFromPhoton()
    UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
    NetworkingPeer:SendMonoMessage(PhotonNetworkingMessage, Object[])
    NetworkingPeer:OnStatusChanged(StatusCode)
    ExitGames.Client.Photon.NConnect:StartConnection()
    ExitGames.Client.Photon.EnetPeer:Connect(String, String, Byte)
    ExitGames.Client.Photon.PhotonPeer:Connect(String, String, Byte)
    NetworkingPeer:Connect(String, String, Byte)
    PhotonNetwork:Connect(String, Int32, String, String)
    PhotonNetwork:ConnectUsingSettings(String)
    PhotonNetMgr:Boot()
    GameManager:Start()

    (Filename: /Applications/buildAgent/work/b0bcff80449a48aa/Runtime/ExportGenerated/MacStandalonePlayer/UnityEngineDebug.cpp Line: 43)
  • Well a workaround wouldn't be hard for me, just wanted to bring it to your attention.
  • Sorry for the (extremely) late reply.
    We had a look at the OnFailedToConnectToPhoton call and made PUN only call it only when the connection wasn't established.

    It's meant to set a flag in your code, as it's also followed by a OnDisconnected (or similarly named) call. You can either handle the individual reasons for a disconnect (like OnFailedToConnectToPhoton), or swallow this info and just handle disconnect. The idea is that disconnect is always called when you actually are disconnected.