How can I detect when a client disconnects

Hi
When i minimize my game in my device, other player confront disconnection after 90 seconds, How can i recognize it in 20 or 30 seconds? is there any configuration in server setup? if it is true, which one?
and is there any other approach to do it?

thanks.

Maybe send a notification/rpc when the game goes inactive?

@morteza You could adjust the socket timeouts to detect the disconnect more quickly but this has a few negative consequences:

  1. You’ll consume more CPU resource if you send more server-side socket heartbeats as well as more network IO resource.
  2. It means you’ll favour players who have better connections because slower connections tend not to manage lots of small messages (like socket heartbeats) well.

The reason our server defaults are set as they are by default is to balance connectivity for players across the world and be more tolerant to slower client connections. The tradeoff is yours of course because you can adjust these values (as we’ve made sure its all configurable).

When i minimize my game in my device, other player confront disconnection after 90 seconds

Another way to solve this problem as a client-side issue rather than server side is to just hook into the application focus lifecycle event in your game engine (like with Unity engine) and intentionally disconnect the socket when the game application loses focus. This will ensure that the other player will observe it immediately.

Hope this helps.

1 Like