SocketException: The descriptor is not a socket

PhotonNetwork.versionPUN = "1.75" , however we've seen this in various prior releases.

On mobile, having sent the application into the background and then restoring it is to generate errors of this type:

Error: Receive issue. State: Connected. Server: '' Exception: System.Net.Sockets.SocketException: The descriptor is not a socket
System.Net.Sockets.Socket.Receive (System.Byte[] buffer)
ExitGames.Client.Photon.SocketUdp.ReceiveLoop ()

It's unclear from the documentation or demos what the correct steps should be to recover following this user action.


  • Tobias
    Tobias admin
    edited September 2016
    Can you let us know which platform this is, exactly? If I had to guess: iOS.

    The error might be coming from the OS when going to the background while reading. In iOS, the app does not have access to sockets when it's in background (unless it's a messenger-type, etc).
    We will take a look.

    You mailed "I've tried brute force disconnect/reconnect and that doesn't seem to help.".
    Does it give you any additional logged errors?

    Please add this to ChatClient.Disconnect() and make sure to call it before you reconnect?
    UnityEngine.Debug.Log("this.HasPeer " + this.HasPeer + " this.chatPeer.PeerState: " + ((this.HasPeer) ? this.chatPeer.PeerState.ToString(): "no peer" ));

    Updated: With info from your mail.
  • I'm fairly sure we can produce this on both iOS and Android. I agree that this relates to the application being sent to and returned from the background. Currently, we're building with Unity 5.3.4p5, have seen this in other builds, and plan on moving to 5.5 assuming it clears beta with a clean bill of health.

    I'm afraid the disconnect/reconnect experiment with so long ago now that I don't recall the error logs that were produced, but I do recall that they were not at all encouraging and so remove it.

    I can certainly add the line of code you mention.
  • I'll take that back: in a quick test, I only reproduced this on iOS and not Android.
  • I guess you were running your previous deploy once again and didn't get the new log's output yet?

    Your finding fits my expectation: iOS will cut off the connection when you go to the background. Like immediately.
    This means to say: I think I know how to reproduce it and will check for a fix. I guess it's a 100% repro case when you put the iOS app into the background (on some reasonably new iOS version)?
  • Absolutely. 100%.
  • As to the rest:

    - Yes, I was running an earlier deployment. I'll let you know if anything interesting appears in logs in later tests.
    - The last test was conducted on a device running iOS 10.0.2
  • I think I already reproduced this but I didn't use Chat.
    I will build a special version to fake the error and then fix the situation, before testing on device to verify.
    FYI: I will be able to spend some time on this today. Monday is a bank holiday, so don't worry if we're off then.
  • Thanks. I look forward to hearing more. We'll be running a QA pass on a build that uses 1.76 and includes your extra log line this evening.
  • > We'll be running a QA pass on a build that uses 1.76 and includes your extra log line this evening.
    Meanwhile I built a socket implementation that throws the exception on demand and in the Chat API of PUN v1.76, I am able to re-connect the ChatClient (using the same values).
    Maybe that's the Editor or Windows / Mono, handling this better.
    I'll check on device.