Regions

Photon Cloud provides you with global connectivity to allow low latency gaming all around the world.

The initial connection of clients goes to a Photon Name Server, which provides the list of available regions.

Each region is completely separate from the others and consists of a Master Server (for matchmaking) and Game Servers (hosting rooms).

Photon Cloud Regions' Connect Flows
Connect to Photon Cloud regions

The full list of available regions is below. In the Dashboard, you can define which regions should be available for the clients.

Contents

Best Region Selection

PUN and Photon Voice rely on the Realtime API layer to pick the Best Region.

Back To Top

C# Realtime API

Photon Realtime can detect the Best Region to connect to and enables you to stick to that region.

To do so, the clients always fetch the list of available regions from the Name Server on connect. This is used to get an up-to-date regions list and check if the saved Best Region -if any- is still available.

After pinging the servers, the results are summarized in a string which should be saved on the device for later use. The summary string includes the current best region, its ping and the current regions list.

Without results from a previous session, all regions will be pinged, which takes a moment longer. If a previous result is available, the client will check:

a. if the region list changed (covers the case if the "previous best region" is still available)
b. if the ping is no longer acceptable (>= 1.5x slower than previously saved reference value)

If either applies, all regions are pinged and a new result gets picked.

Using Best Region works well with the server-side Region Filter in the Dashboard. It enables you to change the list of regions available to players on demand.

To access the list of regions or to override previous results, refer to the API Reference for regions.

Back To Top

Best Region Considerations

"Best Region" option is not deterministic. Sometimes it may be "random" due to little variations or exact same ping calculations.

Theoretically, you could:

  • have the same exact ping to multiple regions from the same device. So its random, if you end up with different regions on clients connected to the same network.
  • different ping values for the same region on different devices (or different retries on the same device) connected to the same network.

For instance, in the case of "us" and "usw" (or "ru" and "rue"), you could either make use of the online regions whitelist to select the ones you want and drop the others or connect to an explicit region.

Back To Top

Available Regions

Photon Cloud has servers in several regions, distributed across multiple hosting centers over the world.

Each Photon Cloud region is identified by a "region token".

To pass the region token with the "Connect" method of your client, call:

    loadBalancingClient.ConnectToRegionMaster(regionString);

List of available regions and tokens:

The strings for region tokens(or codes) are case insensitive. Example: "EU" or "eu" are both accepted and refer to the same Europe region.
RegionHosted inToken
AsiaSingaporeasia
AustraliaMelbourneau
Canada, EastMontrealcae
Chinese Mainland1 (See Instructions)Shanghaicn
EuropeAmsterdameu
IndiaChennaiin
JapanTokyojp
RussiaMoscowru
Russia, EastKhabarovskrue
South AfricaJohannesburgza
South AmericaSao Paulosa
South KoreaSeoulkr
USA, EastWashington D.C.us
USA, WestSan Joséusw

1: Chinese Mainland region needs separate AppId and subscription.

Back To Top

Dashboard Regions Filtering

You can filter the list of available Photon Cloud regions per application on the fly directly from the dashboard.

Photon Cloud: Regions Whitelist
Filter Photon Cloud Regions

Go to the dashboard and then click "Manage" for a chosen application and then click "Edit". You will find an input field where you can enter the list of whitelisted regions as follows:

  • the allowed list should be a string of region tokens separated by semicolons. e.g. "eu;us".
  • region tokens are case insensitive and are defined here.
  • undefined or unrecognized region tokens will be ignored from the list.
  • empty ("") or malformed string (e.g. ";;;") means empty list.
  • empty list means all available regions are allowed.

Once you confirm and save, the operation GetRegions will return only the filtered list of regions. Thus, clients should select from that list but it's fully possible clients connect to any available region explicitly. Take into consideration that dashboard updates propagation can take up to 10 minutes.

Back To Top

How To Choose A Region

Users in the US have the lowest latency if connected to the Photon Cloud US region. Easy.

But what if you have users from all over the world?

You can

  • a) let the game client ping the different Photon Cloud regions and pre-select the one with the best ping, read our how-to
  • b) distribute client builds tied to a region, so users from different regions connect to different Photon Cloud regions or
  • c) let the user choose a matching region from within your game`s UI.

Alternatively, you can d) let all users connect to the same region if the higher latency is acceptable for your gameplay, e.g. with any "not-so-realtime" games.

All Photon Cloud apps are working in all available regions without any extra charge. See pricing.

Photon Cloud's dashboard lets you monitor the usage of your game in each region and easily upgrade or downgrade your subscription plan. Go to your dashboard.

Back To Top

How To Start Your Game With The Lowest Latency

Photon Cloud Regions' Connect Flows
Connect to Photon Cloud regions

Back To Top

Connect To The Nearest Master Server

Direct connections to a master server using the generic region master server address are deprecated. Instead, use the method to connect to a region master as provided by the SDK you are using!

If you know the closest region for your client to connect to you can connect to it passing only the region.

    loadBalancingClient.ConnectToRegionMaster("us");

For other platforms follow the link to the respective SDK and API from the SDKs list.

The SDK will get the master server address for the requested region for you from the name server (1 in the figure "Connect to Photon Cloud regions") and then automatically connect you to the master server in the chosen region (2 in the figure "Connect to Photon Cloud regions").

Back To Top

How To Select A Region At Runtime

If you want to select the region at runtime - e.g. by showing a list of available regions to your players and let them choose - you need to connect to the name server first. You can then query the name server for a list of currently available region master server addresses (1 in the figure "Connect to Photon Cloud regions").

While we write of "the name server", the name server is geographically load-balanced across available regions. That keeps the time to request the master servers' addresses as low as possible.

Back To Top

C# Client SDKs

    loadBalancingClient.ConnectToNameServer()

After a successful connection, you get the list of available regions.

    loadBalancingClient.OpGetRegions()

With the list of master servers, you could now ping all to figure out the best region to connect to for lowest latency gameplay or let your players choose a region.

When your client has determined the region, connect to the master server for that region (2 in the figure "Connect to Photon Cloud regions").

    loadBalancingClient.ConnectToRegionMaster("us")

Finally, join or create a room for your game (3 in the figure "Client Connect to Photon Cloud").

Back To Top

C++ Client SDKs

  1. The Constructor of class Client has a couple of optional parameters. The last one of them, called regionSelectionMode, takes one of the values from LoadBalancing::RegionSelectionMode and defaults to RegionSelectionMode::DEFAULT. Explicitly pass RegionSelectionMode::SELECT for that parameter.

  2. During the connection flow that is triggered by your call to Client::connect(), the client receives a list of available regions from the name server. Listener declares an optional callback Listener::onAvailableRegions(). If you have passed RegionSelectionMode::SELECT for regionSelectionMode, then Client won't automatically choose an item in that list of available regions, but pass the list to that callback. Therefor in your Listener implementation, you should override the empty default implementation of that callback with a meaningful implementation that selects a region based on whatever criteria you can come up with.

  3. The connection flow pauses entirely until you have chosen a region.

  4. Pass your chosen region to Client::selectRegion() to continue the connection flow.

Note: Client::selectRegion() is only expected to be called after you have received a call to Listener::onAvailableRegions() (call selectRegion() either directly from within this callback or later, after the callback has returned). Otherwise, the Client won't be at the correct stage of the connection-flow for region selection.

An example implementation of Listener::onAvailableRegions() can be found in the source code of demo_loadBalancing inside the Client SDK:

void NetworkLogic::onAvailableRegions(const ExitGames::Common::JVector<ExitGames::Common::JString>& availableRegions, const ExitGames::Common::JVector<ExitGames::Common::JString>& availableRegionServers)
{
    EGLOG(ExitGames::Common::DebugLevel::INFO, L"%ls / %ls", availableRegions.toString().cstr(), availableRegionServers.toString().cstr());
    mpOutputListener->writeLine(L"onAvailableRegions: " + availableRegions.toString() + L" / " + availableRegionServers.toString());
    // select first region from list
    mpOutputListener->writeLine(L"selecting region: " + availableRegions[0]);
    mLoadBalancingClient.selectRegion(availableRegions[0]);
}

Note that selectRegion() is only supposed to be called during the connect-flow after the call to onAvailableRegions() has been received. Calling it at any other time or state or calling it multiple times for a single call to onAvailableRegions() is not supported and produces undefined behavior.

Back To Top

Objective-C Client SDKs

  1. The Constructor of class EGLoadBalancingClient has a couple of optional parameters. The last one of them, called regionSelectionMode, takes one of the values from EGRegionSelectionMode.h and defaults to EGRegionSelectionMode_DEFAULT. Explicitly pass EGRegionSelectionMode_SELECT for that parameter.

  2. During the connection flow that is triggered by your call to EGLoadBalancingClient::connect(), the client receives a list of available regions from the name server. EGLoadBalancingListener declares an optional callback EGLoadBalancingListener::onAvailableRegions(). If you have passed EGRegionSelectionMode_SELECT for regionSelectionMode, then EGLoadBalancingClient won't automatically choose an item in that list of available regions, but pass the list to that callback. Therefor in your EGLoadBalancingListener implementation, you should override the empty default implementation of that callback with a meaningful implementation that selects a region based on whatever criteria you can come up with.

  3. The connect flow pauses entirely until you have chosen a region.

  4. Pass your chosen region to EGLoadBalancingClient::selectRegion() to continue the connection flow.

Note: EGLoadBalancingClient::selectRegion() is only expected to be called after you have received a call to EGLoadBalancingListener::onAvailableRegions() (call selectRegion() either directly from within this callback or later, after the callback has returned). Otherwise, the client won't be at the correct stage of the connection-flow for region selection.

An example implementation of EGLoadBalancingListener::onAvailableRegions() can be found in the source code of demo_loadBalancing_objc inside the Client SDK:

- (void) onAvailableRegions:(EGArray*)availableRegions :(EGArray*)availableRegionServers
{
    NSString* r = [availableRegions componentsJoinedByString:@", "];
    NSString* s = [availableRegionServers componentsJoinedByString:@", "];
    EGLOG(EGDbgLvl::INFO, L"onAvailableRegions: %ls / %ls", [r UTF32String], [s UTF32String]);
    [mOutputListener writeLine:@"onAvailableRegions: %@ / %@", r, s];
    // select first region from list
    [mOutputListener writeLine:@"selecting region: %@", availableRegions[0]];
    [mLoadBalancingClient selectRegion:availableRegions[0]];
}

Note that selectRegion() is only supposed to be called during the connect-flow after the call to onAvailableRegions() has been received. Calling it at any other time or state or calling it multiple times for a single call to onAvailableRegions() is not supported and produces undefined behavior.

Back To Top

Using The Chinese Mainland Region

You need to request access to the Chinese Mainland region for your Photon application. Send us an email so we could unlock it for your AppID.
You cannot subscribe to paid plans to be used in the Chinese Mainland region via our website. Reach out to us by email to receive a quote for any subscription.

The Photon Name Server has to be local to China, as the firewall might block the traffic otherwise. The Chinese Photon Name Server is "ns.photonengine.cn".

Connecting with clients from outside of China mainland will most likely not produce good results. Also, connecting from the Photon servers to servers outside of China mainland (e.g. for Custom Authentication, WebHooks, WebRPCs) might not be reliable.

Important: in the current phase, changes you make to your app via your dashboard are not automatically reflected in the app caches for China. Let us know by email if you have an update request there.

Also, for legal reasons, you need a separate build for China and we recommend using a separate AppId with it. For example, use a compile condition (of your choice) to change the AppId and the Photon Name Server depending on the build.

Follow the instructions corresponding to your client SDK to make a special build for the Chinese market.

Back To Top

C# Client SDKs

void ConnectToChina()
{
    loadBalancingClient.NameServerHost = "ns.photonengine.cn";
    loadBalancingClient.AppId = "ChinaRealtimeAppId"; // TODO: replace with your own AppId
    loadBalancingClient.AppVersion = "ChinaAppVersion"; // optional
    loadBalancingClient.ConnectToRegionMaster("cn");
}

Back To Top

C++ Client SDKs

  • Pass "ns.photonengine.cn" for parameter serverAdress to Client::connect().
  • Make sure to keep parameter serverType on its default value of ServerType::NAME_SERVER.

Back To Top

Objective-C Client SDKs

  • Pass "ns.photonengine.cn" for parameter serverAdress to EGLoadBalancingClient::connect()
  • Make sure to keep parameter serverType on its default value of EGServerType_NAME_SERVER.

To Document Top