server | v4 switch to v3  

Client Connection Handling

Client side, Photon is built to give you as much control as possible. This makes sure it integrates well with your game loop.

It also requires some attention to avoid inexplicable disconnects, see also "Connections and Timeouts" in Basic Concepts. The following info should enable you to avoid them.

Disconnect Reasons

Disconnects by Client

  • Client-side timeout (no/too late acks from server).
    • Includes: case if server does not run
  • Client socket exception (connection loss)
  • Client connection fails on receive (buffer full, connection loss)
  • Client connection fails on send (buffer full, connection loss)
  • Note: Using localhost, C# raises exceptions even for UDP!

Disconnects by Server

  • Server-side timeout (no/too late acks from client)
  • Server send buffer full (too many messages)
  • License or Subscription CCU limit hit

There are additional cases when client can't connect at all (bad address, no DNS available). In this context, those are not considered disconnects, because there never was a connection.

Keep Calling Service

To include Photon in your client's game loop, you basically just have to call Service regularly. Regularly means between 10 to 50 times per second (depending on your game / network usage).

Service covers two tasks:

  • Received events and data gets executed. This is done when you can handle the updates. As a sequence order is always kept intact, everything that the client receives is queued and ordered. Service calls DispatchIncomingCommands for this task.
  • Outgoing data of your client is sent to the server. This includes acknowledgments (created in the background) which are important to keep connection to the server. Service internally calls SendOutgoingCommands to do this task. Controlling the frequency of SendOutgoingCommands calls controls the number of packages you use to send a client's produced data.

Profiling Service Calls

To detect if you called Service regularly, we added a statistics module to the client APIs.

If you encounter disconnects, check these values first:

The PhotonPeer.TrafficStatsGameLevel track how often you call DispatchIncomingCommands and SendOutgoingCommands when you turn the stats on (PhotonPeer.TrafficStatsEnabled = true). Check the values of LongestDeltaBetweenSending and LongestDeltaBetweenDispatching.

This feature is implemented in C# based libraries currently. More platforms will get this soon.

Platform Specific Info

Photon Unity SDK

If you use our Photon Unity SDK, you probably do the Service calls in some MonoBehaviour Update method.

To make sure Photon client's SendOutgoingCommands is called while you load scenes, implement a background thread. This thread should pause 100 or 200 ms between each loop, so it does not take away all performance.

 To Document Top