Forum Multiplayer OnDisconnect not raised when connection lost

Discussion and help relating to the PlayerIO Multiplayer API.

OnDisconnect not raised when connection lost

Postby LorenzGames » January 3rd, 2017, 9:23 am

Hi,
I am using Unity for the client.

OnDisconnect doesn't get called when the client loses the connection to internet. For example if the WIFI connection is lost.
Is this a known bug?
LorenzGames
Paid Member
 
Posts: 108
Joined: March 28th, 2010, 3:46 am

Re: OnDisconnect not raised when connection lost

Postby LorenzGames » January 14th, 2017, 10:53 pm

Bump?
LorenzGames
Paid Member
 
Posts: 108
Joined: March 28th, 2010, 3:46 am

Re: OnDisconnect not raised when connection lost

Postby Henrik » January 17th, 2017, 7:10 am

Hey,

Which version of Unity are you using, and on what platforms are you seeing this behaviour?

What happens if you try to send a message when you know the network has been lost?

If it's a mobile device, is it switching to mobile internet when you switch off the wifi?
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: OnDisconnect not raised when connection lost

Postby LorenzGames » January 17th, 2017, 8:41 am

Henrik wrote:Hey,

Which version of Unity are you using, and on what platforms are you seeing this behaviour?

What happens if you try to send a message when you know the network has been lost?

If it's a mobile device, is it switching to mobile internet when you switch off the wifi?


Hi Henrik,

I am experiencing the issue with Unity 5.4.3f1 on a Mac.
If I join a room, then turn off wifi and try to send a message, nothing happens, disconnect is never called.
The only way to trigger the OnDisconnect event is for me to manually call connection.Disconnect();
LorenzGames
Paid Member
 
Posts: 108
Joined: March 28th, 2010, 3:46 am

Re: OnDisconnect not raised when connection lost

Postby LorenzGames » January 28th, 2017, 9:43 am

Hi Henrik, any clue why that would be happening?
LorenzGames
Paid Member
 
Posts: 108
Joined: March 28th, 2010, 3:46 am

Re: OnDisconnect not raised when connection lost

Postby Henrik » February 2nd, 2017, 11:35 pm

Hey Lorenz,

We're looking into this issue.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: OnDisconnect not raised when connection lost

Postby LorenzGames » February 19th, 2017, 6:49 am

Hi, sorry to bump this again, were you guys able to understand what is going on?
LorenzGames
Paid Member
 
Posts: 108
Joined: March 28th, 2010, 3:46 am

Re: OnDisconnect not raised when connection lost

Postby Henrik » February 22nd, 2017, 10:55 pm

Hey,

The way our client detects disconnects is if either the TCP stack signals that the connection is broken, or if a TCP-level keep-alive fails for a certain amount of time.

Both of these features require that the TCP stack have support for it, and we've had issues before with Unity's implementation of it, so I wouldn't be surprised if either of these features don't work properly when you deploy to an iOS device.

The default keepalive detection time is 25s on a standard Windows PC, have you tried waiting that long or longer in your app when you've been testing disconnects?
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: OnDisconnect not raised when connection lost

Postby LorenzGames » February 23rd, 2017, 7:25 pm

Is there a way to make the keep alive shorter?
Also this is happening everywhere, not just iOS.
LorenzGames
Paid Member
 
Posts: 108
Joined: March 28th, 2010, 3:46 am

Re: OnDisconnect not raised when connection lost

Postby Henrik » February 24th, 2017, 2:09 am

The drawback to using keepalives is that it's consuming more bandwidth the more often you check, which is something other games might not want. We've put in a sensible default in the SDK that's trying to be one-size-fits-all.

If your game requires a shorter keepalive, I think the best way is for you to implement it yourself. Make your client send a simple "ping" message at some interval, make your game server message handler respond to those with a "pong" message, and finally, in your client, check if you haven't received those in a while, and disconnect/reconnect the user if so.

Unity also has some support classes that can tell you the connectivity state of the device that you can use:

https://docs.unity3d.com/ScriptReferenc ... ility.html
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm


Return to Multiplayer