Sign In Register

How can we help you today?

Start a new topic

Android - Real time session

Hi, just started learning Game sparks sdk and able find a match making. Can any one share a snippet that creates real time session and send packets between connected players..


Hi Ramesh,


The code I'm providing here will need to re worked for your individual case, but the basic principals will remain the same.


On Match Found should look something like this. This will create the real time session.

        private void OnMatchFound(GameSparks.Api.Messages.MatchFoundMessage message)

        {

            _gameSparksManager.StartNewRtSession(

                new RtSessionInfo(message),

                OnPlayerConnect,

                OnPlayerDisconnected,

                OnRtReady,

                OnPacketReceived

            );

        }


On Real Time session ready. I send a packet here just to demonstrate.

        private void OnRtReady(bool ready)

        {

            if (!ready) return;

            var data = new RTData();

            data.SetLong(1, (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds);

            _gameSparksManager.GameSparksRtUnity.SendData(101, GameSparksRT.DeliveryIntent.RELIABLE, data, 0);

        }


On Packet Received. 

        private void OnPacketReceived(RTPacket packet)

        {

            Debug.Log(packet.ToString());

        }


The relevant Real Time Code Cloud to use here could be something like

RTSession.onPacket(101, function(packet){


    RTSession.newPacket().setData(

        RTSession.newData()

        .setNumber(1, packet.getData().getNumber(1))

        .setNumber(2, new Date().getTime()))

        .setOpCode(101)

        .setTargetPeers(packet.getSender().getPeerId())

        .send();

});


I haven't included the OnPlayerConnect and Discconect but for the purpose of testing these can be private static methods.


Hope this helps,

 - Steve

Hi Ramesh,

Are you using our Unity SDK (as in Steve's response) or our Android SDK?
There is currently no real-time support of our Android SDK.

Sean

 

Hi,

I read somewhere a couple of months ago, one of the staff saying Android real-time is coming soon.
How soon can we get this please? been waiting for it since forever.

Login to post a comment