Skip to main content

 Show Sidebar

Realtime Intro

Get Started

Photon Realtime is a fully managed service (SaaS) of Photon onpremise servers running in regions worldwide, ready for low latency multiplayer gaming around the globe, anytime.

Use the multiplayer API from Photon Realtime to join many players together in a shared game session and transfer data and messages synchronously, in real-time, between connected players across platforms. All client SDKs can interact with each other, no matter if iOS, Android, Web or standalone.

Connect

Photon Realtime applications need a distinct application and AppId to connect to. Get your AppId from the Realtime Dashboard after free signup.

With an AppId at hand you are ready to Connect your LoadBalancingPeer instance.

```csharp using ExitGames.Client.Photon;

public class MyClient : IPhotonPeerListener
{
    LoadBalancingPeer peer;

    public bool Connect()
    {
        peer = new LoadBalancingPeer(this, ConnectionProtocol.Udp);
        if (peer.Connect("app-eu.exitgamescloud.com:port", AppId))
        {
            return true;
        }

        // connect might fail if e.g. the address format is bad.
        return false;
    }
}

```

You pass Connect the application ID and region you would like to connect to. Click here for a list of available regions.

Matchmaking

Create a Game

To create a new room, aka game, invoke OpCreateRoom on your connected LoadBalancingPeer.

csharp peer.OpCreateRoom("Room 42", 2, customGameProperties, propertiesListedInLobby);

Pass OpCreateRoom the room name and amount of players to start with. The newly created room is entered immediately and exists until the last player has left.

Custom values are attached to a room as custom properties, optionally passed when connecting. Common examples for room properties include the map name, level or the round duration.

Select any of your custom properties to be shown in the lobby handing in an optional array with their names. Properties showing in the lobby can be used for matchmaking and as filter for random matches.

Find a Game

Clients join games by name or ask Photon to find a perfect match.

Find rooms ...

  • by Random: Matches players randomly. Optionally fills rooms or distributes players evenly.
  • Filters can be used for better matching.
  • by Listing: The lobby lists visible rooms to let players pick and join manually.
  • that are Private: Join hidden rooms that you know the name of.
  • or Parameterized: Customize random matching by defining expected properties.

csharp // join random rooms easily, filtering for specific room properties, if needed Hashtable expectedCustomRoomProperties = new Hashtable(); expectedCustomRoomProperties["map"] = 1; // custom props can have any name but the key must be string peer.OpJoinRandomRoom(expectedCustomRoomProperties, (byte)expectedMaxPlayers);

Gameplay

Sending Events

Whatever happens on one client can be sent as event to update everyone in the same room. Update your players with stats, positions or your current turn. Photon will send it as fast as possible via, optionally reliable, UDP, TCP or Websockets.

  • Send messages/events: Send any type of data to other players.
  • Player/Room properties: Photon updates and syncs these, even to players who join in later.

csharp byte eventCode = 1; // make up event codes at will Hashtable evData = new Hashtable(); // put your data into a key-value hashtable bool sendReliable = false; // send something reliable if it has to arrive everywhere byte channelId = 0; // for advanced sequencing. can be 0 in most cases peer.OpRaiseEvent(eventCode, evData, sendReliable, channelId);

Receiving Events

Whenever an event is dispatched the OnEvent handler is called.

csharp peer.OnEvent(eventData);

Each event carries its specific content in its EventData parameters. Your application knows which content to expect by the Code passed with the EventData.

For an up-to-date list of default event codes look for the EventCode constants in your SDK, e.g. within ExitGames.Client.Photon.LoadBalancing.EventCode for C#.

Custom or Authorative Server Logic

As is, without authorative logic, Photon Cloud products already allow for a broad range of game types.

  • First Person Shooters
  • Racing Games
  • Minecraft type of games
  • Casual real-time games
  • Asynchronous and synchronous games
  • ...

Use Photon Server to implement your own custom logic.

Get in contact for early access on custom logic with Photon Turnbased, Photon Chat or Photon Realtime using Webhooks, Web RPC or Plugins.

Getting Help

If you've got questions, curiosities, ... or your app doesn't work but you really wish it would, try any of these:

Get in Touch

We'd love to know what you want to read and see in our docs, whether that is more demos, specific documentation, an FAQ or example applications. If there's something you'd like to see that's not already in drop us your suggestion to developer@exitgames.com.

Want to learn more about Photon?

Get started, Sign up free
Find us at these events and venues.
Request a meeting.

 To Document Top