Regions with Corona

Hi,

I’m almost finish my game but for the end I left this:

http://doc.photonengine.com/en-us/realtime/current/reference/regions 

And I don’t understand how to make in Corona SDK automatically selecting best region.

Master server is selected at the beginning

local client = LoadBalancingClient.new(masterAddress, appId, appVersion)

So, how to solve my problem?

Automatic region selection is not supported by Photon Corona SDK. You may select server by connecting to every known region master server and measuring the ping or ask user to choose region manually.

To be able to work with regions, you need to connect to nameserver first .

  1. Set serverAddress to ‘ns.exitgames.com:5058’ in LoadBalancingClient constructor (http://doc-api.photonengine.com/en/corona/current/modules/loadbalancing.LoadBalancingClient.html#new)

  2. Call client.connectToRegionMaster(“region code”) to connect region with known code.

  3. Alternatively, you can connect with client.connectToNameServer() and when client’s state changed to LoadBalancingClient.State.ConnectedToNameServer (in client:onStateChange), request regions list with client.getRegions(). Since current region list is well known and rarely updated, you hardly need this step.

Hmm, I don’t think that I understand everything. I did this:

local masterAddress = "ns.exitgames.com:5058" local appId = "my app id" local appVersion = "1.0" local client = LoadBalancingClient.new(masterAddress, appId, appVersion)

and then instead client:connect() I did client.connectToRegionMaster(“us”) to see how that works. And that gives me an error:

Attempt to call method 'isConnectedToNameServer' (a nil value) File: plugin\_photon.lua Line: 8030

And for the third point. After client.getRegions() I need to ping each region? How to make it?

ns.exitgames.com:5058” is the address of nameserver. ‘nameserverAddress’ is more appropriate name for the variable.

Please send full application log and call stack of error.

Does demo-particle work for you? It does exactly the same - calls connectToRegionMaster().

Command-line demo turnbased.lua (run ‘lua turnbased.lua’ from ‘demo-console’ folder) also shows Getregions() usage.

As soon as client is connected to the master (LoadBalancingClient.State.ConnectedToMaster state), you can call client.masterPeer:getRoundTripTime() which returns time required to send last operation to a server and get response from it. Note that ‘masterPeer’ property is not a part of public api currently but still can be safely used.

You can also try to send some requests to master server before measuring rtt. E.g. call client:requestLobbyStats() after getting to LoadBalancingClient.State.JoinedLobby state and read result in client:onLobbyStats()

Thank you for response. I looked at my code second time and…instead client:connectToRegionMaster(“US”)  I did it: client.connectToRegionMaster(“US”) so that was my mistake. After that I saw that my game didn’t need custom regions because latency is not bad.

Automatic region selection is not supported by Photon Corona SDK. You may select server by connecting to every known region master server and measuring the ping or ask user to choose region manually.

To be able to work with regions, you need to connect to nameserver first .

  1. Set serverAddress to ‘ns.exitgames.com:5058’ in LoadBalancingClient constructor (http://doc-api.photonengine.com/en/corona/current/modules/loadbalancing.LoadBalancingClient.html#new)

  2. Call client.connectToRegionMaster(“region code”) to connect region with known code.

  3. Alternatively, you can connect with client.connectToNameServer() and when client’s state changed to LoadBalancingClient.State.ConnectedToNameServer (in client:onStateChange), request regions list with client.getRegions(). Since current region list is well known and rarely updated, you hardly need this step.

Hmm, I don’t think that I understand everything. I did this:

local masterAddress = "ns.exitgames.com:5058" local appId = "my app id" local appVersion = "1.0" local client = LoadBalancingClient.new(masterAddress, appId, appVersion)

and then instead client:connect() I did client.connectToRegionMaster(“us”) to see how that works. And that gives me an error:

Attempt to call method 'isConnectedToNameServer' (a nil value) File: plugin\_photon.lua Line: 8030

And for the third point. After client.getRegions() I need to ping each region? How to make it?

ns.exitgames.com:5058” is the address of nameserver. ‘nameserverAddress’ is more appropriate name for the variable.

Please send full application log and call stack of error.

Does demo-particle work for you? It does exactly the same - calls connectToRegionMaster().

Command-line demo turnbased.lua (run ‘lua turnbased.lua’ from ‘demo-console’ folder) also shows Getregions() usage.

As soon as client is connected to the master (LoadBalancingClient.State.ConnectedToMaster state), you can call client.masterPeer:getRoundTripTime() which returns time required to send last operation to a server and get response from it. Note that ‘masterPeer’ property is not a part of public api currently but still can be safely used.

You can also try to send some requests to master server before measuring rtt. E.g. call client:requestLobbyStats() after getting to LoadBalancingClient.State.JoinedLobby state and read result in client:onLobbyStats()

Thank you for response. I looked at my code second time and…instead client:connectToRegionMaster(“US”)  I did it: client.connectToRegionMaster(“US”) so that was my mistake. After that I saw that my game didn’t need custom regions because latency is not bad.