Photon——Client Connection Handling 客户端连接处理

 

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.
     客户端,Photon给予你更多可能的控制。这确保了它很好的集成你的游戏循环。它还需要关注避免一些异常的断开。下面的信息可以帮助你避免他们。
 

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).
     在你的游戏客户端中包含Photon,你只需要定期调用服务。大概是每秒10到50次。
 
     Service covers two tasks:
  • Received events and data are 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 acknowledgements (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.
      服务涵盖2个任务:
  • 接收被执行的事件和数据,当你处理更新的时候进行。作为一个顺序序列总是保持完好。客户端接收到的所有东西是被排序和队列化的。服务调用DispatchIncomingCommands完成这个任务
  • 你的客户端发送传出数据给服务端。这包括确认保持着服务端的连接。服务在内部调用SendOutgoingCommands 完成这个任务。控制调用SendOutgoingCommands控制发送客户端产生数据包数量的频率

Profiling Service Calls 剖析服务调用

     To detect if you called Service regularly, we added a statistics module to the client APIs.
     如果你定期调用服务去检测,我们添加了一个模块到客户端API中。
 
     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.
     如果你发生了断开,首先检查这些值:当你打开统计时,TrafficStatsGameLevel 跟踪DispatchIncomingCommands和SendOutgoingCommands的调用,检查LongestDeltaBetweenSending和LongestDeltaBetweenDispatching的值。
 
     This feature is implemented in C# based libraries and Android currently. More platforms will get this soon. PUN has a GUI component for this: PhotonStatsGui.
     这个特性是用c#的基础库和Android实现的。更多的平台将很快也能实现这个。PUN有一个GUI组件:PhotonStatsGui。
 

Platform Specific Info 平台特定的信息

     Unity3d and PUN 

     The Photon Unity Networking package implements the Service calls for you: PhotonHandler.Update calls Service in intervals.However, Unity won’t call Update while it’s loading scenes (or maybe even any assets).
     Photon Unity 网络通信包为你实现服务的调用:PhotonHandler.Update定期调用服务。然而,Unity不会调用更新在加载场景的时候。
 
     To keep the connection while loading scenes, you should set PhotonNetwork.IsMessageQueueRunning = false.
     在加载场景的时候要保持连接,你必须设置PhotonNetwork.IsMessageQueueRunning为false

     Pausing the message queue has two effects:

  • A background Thread will be used to call SendOutgoingCommands while Update is not called. This keeps the connection alive, sending acknowledgements only but no events or operations (RPCs or sync updates). Incoming data is not executed by this Thread.
  • All incoming updates are queued. Neither RPCs are called, nor are observed objects updated. While you change the level, this avoids calling RPCs in the previous one.
     暂停消息队列有2个效果:
  • 后台线程被用于调用SendOutgoingCommands时更新未被调用。这个保证了连接,发送确认但没有事件或操作。在这个线程里传入数据不被执行。
  • 所有的传入更新被排队。RPCs被调用。也不是查看对象的更新,当你改变了级别时,这避免了调用RPCs在前面一个。

     Unity3d

     If you use the “plain” from our Unity Client SDKs, you implemented Service most likely in some MonoBehaviour Update method.To make sure Photon’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.
     如果你使用了Unity客户端SDK包中的plain,在一些MonoBehaviour Update 方法中你实现服务。去确保在你加载场景的时候Photon的SendOutgoingCommands被调用。现实一个后台线程。这个线程在循环间暂停100或200毫秒,所以它不会影响性能。

你可能感兴趣的:(Connection)