Understanding GameSparks Real-Time

This tutorial provides an introductory overview for working with GameSparks real-time.

Creating a Real-Time session

Real-Time sessions are dependent on Real-Time matches. A Match must be configured to support a real-time session once it is found. When a Match has been found, a MatchFoundMessage will be sent to the players involved with three important variables:

These three variables are what a client needs to establish a connection to the Real-Time session.

The GameSparks SDK has the Create Session function that allows you to connect to a session using the Port Number, Access Token, and Host Server.

The session comes with four useful Events, which help you to organize players, manage games and logic, and use data sent to or from the server or other peers:

In addition to these Events, you also have Stop, Start, GetPeers and Send functions:

Packets and Connection

Real-Time sessions have access to every part of the backend and can execute logic on behalf of any player. You can add logic to your server by creating a Real-Time script in the Cloud Code section and configuring the Match to use that script.

You can place logic in the script that reacts to packets, to players connecting, and to players disconnecting using the same functions:

The packets sent and received have four attributes:

Important! Note that OpCode 0 Does not work. Do not address Packets with OpCode 0.

Example

To retrieve Data from a packet you would use Has Type and Get Type functions. For example, if you were trying to retrieve a string from index 20 you would:

Summary

Did this page help you? Please enter your feedback below. For questions about using this part of the platform, please contact support here