Server disconnect timeout

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Server disconnect timeout

GLeBaTi
2016-09-30 11:46:04

Hello. I have android game with photon. Android games is not working in background (android specific)
When i hide(minimize) the game, after 10 seconds i have on server:

OnDisconnect - ConnID=52 reasonCode=ClientDisconnect Connection state changed from Connected to Disconnected OnDisconnect: conId=109.195.243.29, reason=ClientDisconnect, reasonDetail= IUMobilePeer: User disconnected Connection state changed from Disconnected to Disposed

On client (when i open the game (maximize)):

PhotonDebugReturn: Receiving failed. SocketException: WouldBlock Status code:InternalReceiveException Status code:Disconnect

How can i increase timeout?

Comments

JohnTube
2016-09-30 14:24:44

Hi @GLeBaTi,

If you want to debug Photon clients connected to self-hosted Photon Server visit this link.

GLeBaTi
2016-09-30 14:38:29

@JohnTube thanks for reply
I am not using PUN (i am using PhotonPeer directly)
InactivityTimeout = "0" not solve my problem :/

chvetsov
2016-10-03 07:32:25

I assume you are using native sdk for android, right?

GLeBaTi
2016-10-03 10:33:57

@chvetsov wrote:

I assume you are using native sdk for android, right?

No, i am using Photon Unity3d SDK

GLeBaTi
2016-10-03 10:50:53

I found in "https://doc.photonengine.com/en/realtime/current/reference/known-issues" :

Mobile - Home Button Causes Disconnect

On (most) mobiles, applications are not allowed to keep a connection when they are in the background. There are next to no exceptions to this rule (e.g. see Background Execution on the Apple dev pages).

When a game gets focus again within (approximately) 10 seconds, PUN will try to continue the game. Any pause longer than that will lead to a timeout. There is a chance that the server side timed out the client meanwhile.

Due to the nature of iOS also shutting down the app immediately, a "timeout disconnect" callback naturally gets known to your app only when it's executing again.

There are system callbacks by iOS when an application goes to the background and when it gets focus again. Use those to disconnect. If the game design can allow a player to return even after several seconds or minutes, then you could also re-connect and join the game again.

JohnTube
2016-10-04 09:03:09

@GLeBaTi is there a reason why you use the "low level" PhotonPeer "directly" from the Realtime Unity SDK? Why not use LoadBalancingClient (extend it maybe?) or LoadBalancingPeer?

Currently, the background thread is available in PUN only.

@Tobias what do you think?

GLeBaTi
2016-10-04 10:27:20

Becouse i have only one server. I don't need load balancing/
background threads also not working in background in android.
Now i make reconnect on game gets focus again.

sid_juego
2017-05-22 08:57:19

Bump... any updates on this guys?
I too am facing the same issue.

chvetsov
2017-05-22 15:27:37

hi, @sid_juego
you may either reconnect as @GLeBaTi did
or ask in dotnet client forum.

best,
ilya

sid_juego
2017-05-24 11:55:53

///


/// Defines how many seconds PUN keeps the connection, after Unity's OnApplicationPause(true) call. Default: 60 seconds.
///

///
/// It's best practice to disconnect inactive apps/connections after a while but to also allow users to take calls, etc..
/// We think a reasonable backgroung timeout is 60 seconds.
///
/// To handle the timeout, implement: OnDisconnectedFromPhoton(), as usual.
/// Your application will "notice" the background disconnect when it becomes active again (running the Update() loop).
///
/// If you need to separate this case from others, you need to track if the app was in the background
/// (there is no special callback by PUN).
///
/// A value below 0.1 seconds will disable this timeout (careful: connections can be kept indefinitely).
///
///
/// Info:
/// PUN is running a "fallback thread" to send ACKs to the server, even when Unity is not calling Update() regularly.
/// This helps keeping the connection while loading scenes and assets and when the app is in the background.
///
/// Note:
/// Some platforms (e.g. iOS) don't allow to keep a connection while the app is in background.
/// In those cases, this value does not change anything, the app immediately loses connection in background.
///
/// Unity's OnApplicationPause() callback is broken in some exports (Android) of some Unity versions.
/// Make sure OnApplicationPause() gets the callbacks you'd expect on the platform you target!
/// Check PhotonHandler.OnApplicationPause(bool pause), to see the implementation.
///

and now, where exactly is "PhotonHandler.OnApplicationPause" ??

Back to top