Unity NotificationListener not receiving updatePeers()

0 votes
Hi we have an AppWarpS2 game server live.

We are developing a Unity app to receive move messages from the server for quiz game.

Our current situation is:

Server waits for client connections

Receives 2 add user requests

Creates a room for 2 users

Joins users to the room

Add users to subscribe to room

and receives start game packet from both users

Then broadcasts quiz to both users

 

Our problem is that everything works fine on the native Windows Phone but on Unity we are not receiving the onUpdatePeersReceived message?

Here is handleUpdatePeersRequest on server

    public void handleUpdatePeersRequest(IUser sender, byte[] update, HandlingResult result)
    {
        System.out.println("In handleUpdatePeersRequest" + " sender = " + sender.getName());
        try
        {
            result.sendNotification = false;
            int size;
            byte[] fbInvitation;
            String fbObject;
            JSONObject invObject;
            IoBuffer buf = IoBuffer.allocate(update.length, false);
            buf.setAutoExpand(true);
            buf.put(update, 0, update.length);
            buf.flip();
            buf.position(0);
            byte bt = buf.get();
            switch (bt)
            {
                case QuizRequestCode.STARTQUIZ:
                    StartQuizFlag++;
                    System.out.println("Received Start Quiz Packet" + StartQuizFlag + "RoomId " + this.gameRoom.getId()
                            + " sender = " + sender.getName());
                    break;
                case QuizRequestCode.ANSWERPACKET:
                    System.out.println("Answer Received " + bt);
                    for (int i = 0; i < UserStatusList.size(); i++)
                    {
                        if (UserStatusList.get(i).getUser().getName().equalsIgnoreCase(sender.getName()))
                        {
                            // ID of the last question asked on client
                            int queID = buf.getInt();
                            // int representing the answer response to previously asked question
                            int ans = buf.getInt();
                            // If this answer is for the game current question
                            if (UserStatusList.get(i).getAnswersPerLevel().size() == GameCurrentLevel)
                            {
                                System.out.println("ANSWERPACKET if statement & getAnswersPerLevel().size() == GameCurrentLevel: " + GameCurrentLevel);
                                // Then add new QuizAnswer element to their answered questions array for this game
                                UserStatusList.get(i).getAnswersPerLevel().add(new ArrayList<QuizAnswer>());
                            }
                            // Get the total number of questions now answered in this game
                            int currentSize = UserStatusList.get(i).getAnswersPerLevel().get(GameCurrentLevel).size();
                            
                            QuizAnswer userAnswer = new QuizAnswer(queID, ans);
                            if (currentSize == 0)
                            {
                                System.out.println("ANSWERPACKET if statement & currentSize == 0");
                                UserStatusList.get(i).getAnswersPerLevel().get(GameCurrentLevel).add(userAnswer);
                                updateAndBroadCastScore(i, queID - 1, ans);
                            }
                            else if (UserStatusList.get(i).getAnswersPerLevel().get(GameCurrentLevel).get(currentSize - 1).QuestionId != queID)
                            {
                                System.out.println("ANSWERPACKET else if getAnswersPerLevel().get(GameCurrentLevel).get(currentSize - 1).QuestionId != queID - queID = " + queID);          
                                UserStatusList.get(i).getAnswersPerLevel().get(GameCurrentLevel).add(userAnswer);
                                updateAndBroadCastScore(i, queID - 1, ans);
                            }
                        }
                    }
                    break;
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

Here is sendQuestion on server:

    private void SendQuestion()
    {
        System.out.println("In SendQuestion()");
        QuizTimerCount = 0;
        GameCurrentQuestion++;
        byte[] questionPacket = getNextQuestionPacket();
        for (int i = 0; i < UserStatusList.size(); i++)
        {
            UserStatus user = UserStatusList.get(i);
            System.out.println("Sending Question to User "+user.getUser().getName().toString());
            user.getUser().SendUpdatePeersNotification(questionPacket, true);
        }
    }

 

Here is onUpdatePeersRequest in Unity (this is not being called on Unity but is called on native Windows Phone client)

    public class NotificationListener : com.shephertz.app42.gaming.multiplayer.client.listener.NotifyListener
    {

        public void onUpdatePeersReceived(UpdateEvent eventObj)
        {
            UnityEngine.Debug.Log("In onUpdatePeersReceived");
            // This is the incoming move - parse it in MoveMessage
            MoveMessage.buildMessage(eventObj.getUpdate());
        }
........

}

We define our global context in Unity:

        public static RoomReqListener roomReqListenerObj;
        public static NotificationListener notificationListenerObj;
        public static ZoneRequestListener zoneRequestListenerobj;
        public static ConnectionListener conListenObj;

The connection and listeners are initialised in Unity:

    public static class AppWarpS2Connection
    {
        // Connect to server
        public static void InitialiseConnection()
        {
            Debug.Log("In AppWarpS2Connection InitialiseConnection");
            WarpClient.initialize(GlobalContext.API_KEY, GlobalContext.HOST_NAME);
            // Allow for some connection resiliency = 60 seconds
            WarpClient.setRecoveryAllowance(60); //<-----------------------------------------------------------
            GlobalContext.warpClient = WarpClient.GetInstance();
        }

        // Setup our listeners
        public static void InitialiseListeners()
        {
            Debug.Log("In AppWarpS2Connection InitialiseListeners");
            GlobalContext.conListenObj = new ConnectionListener();
            GlobalContext.warpClient.AddConnectionRequestListener(GlobalContext.conListenObj);

            if (GlobalContext.roomReqListenerObj == null)
            {
                Debug.Log("In AppWarpS2Connection Initialise RoomRequestListener");
                GlobalContext.roomReqListenerObj = new RoomReqListener();
                GlobalContext.warpClient.AddRoomRequestListener(GlobalContext.roomReqListenerObj);
            }

            if (GlobalContext.notificationListenerObj == null)
            {
                Debug.Log("In AppWarpS2Connection Initialise NotificationListener");
                GlobalContext.notificationListenerObj = new NotificationListener();
                //WarpClient.GetInstance().AddNotificationListener(GlobalContext.notificationListenerObj);
                GlobalContext.warpClient.AddNotificationListener(GlobalContext.notificationListenerObj);
            }

            if (GlobalContext.zoneRequestListenerobj == null)
            {
                Debug.Log("In AppWarpS2Connection Initialise ZoneRequestListener");
                GlobalContext.zoneRequestListenerobj = new ZoneRequestListener();
                //WarpClient.GetInstance().AddZoneRequestListener(GlobalContext.zoneRequestListenerobj);
                GlobalContext.warpClient.AddZoneRequestListener(GlobalContext.zoneRequestListenerobj);
            }
        }
    }
}

I'm confused and can't see why onUpdatePeersReceived in Unity is not being called? Please help.

Using Unity 5.1.1f1 personal

Using AppWarpS2Unity.dll

Many thanks
asked Nov 9, 2015 in AppWarpS2 by wiredvoltage (84 points)
recategorized Nov 9, 2015 by wiredvoltage
Update:

We can give you a link to our current unity build on dropbox if you want to take a look at the problem?

Thanks

1 Answer

0 votes

Hi,

I tested the same at my end and it is working fine in our samples such as Quiz sample. Please make sure you are using AppWarpS2Unity.dll not AppWarpS2UnityWP8.dll or AppWarpS2UnityMobile.dll.

To debug, you can put some server side logs in handleUpdatePeersRequest and check for the issue it might have.

Let me know if the problem continues.

Thanks.

answered Nov 10, 2015 by rajeev.etc (1,660 points)
Hi rajeev, I have trace the following:

Join room= SUCCESS
Subscribe room = SUCCESS
Get live room info = SUCCESS
Send start quiz packet = TRUE
Receive start quiz packet = TRUE
Send level start packet = TRUE
Receive level start packet = FALSE (in onUpdatePeersReceived)

I'm totally baffled why the event is not raised when the server is actually broadcasting it? Any other help weclome here?


Thanks
Found it....

WarpClient.GetInstance().Update();

Is needed in Unity!
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...