How to Handle Disconnections (Advanced)

ADVANCED DISCONNECTION HANDLING: While the previous integration steps will get you up and running with synchronous development, your game must implement all six disconnect methods from the SyncDelegate in order to be playable in a mobile environment and ensure a fair and consistent playing experience for your users.

You can use these functions to control the state of the game on both devices such as pausing and un-pausing the game when a user loses or re-establishes connection.

OnCurrentPlayerHasLostConnection

  • This method will be called when the current player has lost their connection to the Skillz Server, either by backgrounding their app or losing signal.
  • You can use this to notify the current player that they have lost connection.
  • Note: As the SDK will try to reestablish a connection to the server on its own, there is no specific action the game needs to perform in this situation. 
  • Recommended: Use getTimeLeftForReconnection to display UI updates. We recommend showing this time to all users when either loses connection so that both of them know that there is a time limit to reconnect.
  • Note: If the current player has been disconnected from the server for over 30 seconds over the entire duration of the match, the current player will receive a call to onCurrentPlayerHasLeftMatch, which should trigger an abort. 

OnCurrentPlayerHasReconnected

  • This method is called when a disconnected current player reconnects to the server within the allotted time.
  • You can use this method to resume play in a game that had been paused when the current player disconnected.
  • Note: Upon reconnecting, getTimeLeftForReconnection will NOT be reset. This value will stop counting down, but will always be strictly decreasing to prevent griefing.

OnCurrentPlayerHasLeftMatch

  • This method is called when the current player disconnects from the server and does not reconnect within the allotted time. This will remove them from the match.
  • Recommended: You should implement this method and abort the current player from the match.

OnOpponentHasLostConnection

  • This method will be called when the opponent player has lost their connection, either by backgrounding their app or losing signal. This method is not called when the game is finished nor when the opponent aborts the match.
  • You can use this to pause the match until the disconnected player is either reconnected or kicked if they do not reconnect within the allotted time.
  • Recommended: Use getTimeLeftForReconnection to display UI updates. We recommend showing this time to all users when either loses connection so that both of them know that there is a time limit to reconnect.
  • Note: If an opponent player is disconnected from the server for over 30 seconds over the total duration of the match, the current player will receive a call to onOpponentHasLeftMatch, which should trigger an abort.
  • Note: If the current player is also disconnected, they will not receive onOpponentHasLostConnection until they reconnect - the onOpponentHasLostConnection is triggered by a new disconnect message from the server.

OnOpponentHasReconnected

  • This method is called when a disconnected opponent player reconnects to the server within the allotted time.
  • You can use this method to resume play in a game that had been paused when the player disconnected.
  • Note: Upon reconnecting, getTimeLeftForReconnection will NOT be reset. This value will stop counting down, but will always be strictly decreasing to prevent griefing.

OnOpponentHasLeftMatch

  • This method is called when the opposing player disconnects from the server and does not reconnect within the allotted time. This will remove them from the match.
  • Recommended: You should implement this method to halt the game and report the current player's current score.
  • Note: This is also called if the opponent player aborts their match.