Denis Covaci
Denis Covaci

Reputation: 1167

Android Realtime Multiplayer notify connection lost

I am using RealTime Multiplayer to create an Android game from here:
https://developers.google.com/games/services/android/realtimeMultiplayer

If two players are connected to a room, and the Internet Connection of one of them is interrupting, i want the other player to get notified.

Currently i don't see any listener that is called when a connection with other player has been lost.

Is there any way to manage this?

Upvotes: 1

Views: 262

Answers (3)

Muhammad Abbas Khan
Muhammad Abbas Khan

Reputation: 191

It is a workaround but you an try,

  1. You can repeatedly send massages from both the players to ensure that the players are connected to network say every 1000 milliseconds,

  2. If you didn't get a message for say 2000 milliseconds then there might be an error at the other players end

Upvotes: 2

AndroidEnthusiastic
AndroidEnthusiastic

Reputation: 931

Create a listener and check network changes

// Indicates the state of Wi-Fi P2P connectivity has changed.
intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);

Upvotes: 0

Mohammad Khan
Mohammad Khan

Reputation: 581

I have used RealTimeMultiplayer.ReliableMessageSentCallback interface implemented at the activity and have used workaround this in the following way

 @Override
        public void onRealTimeMessageSent(int statusCode, int tokenId, String recipientParticipantId) {
            switch (statusCode) {

                case GamesStatusCodes.STATUS_OK:
                    messageSent = true;
                    break;

                case GamesStatusCodes.STATUS_REAL_TIME_ROOM_NOT_JOINED:
                    break;

                case GamesStatusCodes.STATUS_REAL_TIME_MESSAGE_SEND_FAILED:
                    messageSent = false;
                    break;

            }
        }

but still the GamesStatusCodes.STATUS_REAL_TIME_MESSAGE_SEND_FAILED gets called after say 15 to 30 seconds later

Upvotes: 3

Related Questions