Product Overview 产品概述


     On the client-side, Photon supports various platforms. Even though
programming in C, C# and Flash is very different, the basic workflow
stays similar. In this online documentation we try to explain the
concepts and background, while language specifics are left to the
reference documentation per platform.



     Each Photon Client SDK comes with a fitting reference documentation
for its platform and language.


     Project Setup 项目设置


     You need to include a single library to communicate with Photon on
the client-side. This is a different setup per platform.

     在客户端你需求包蕴叁个单独的library ,各种平台的设置是差异的。

  • DotNet

     Add a reference to the PhotonDotNet.dll in your DotNet project to
make its classes known. Import the lib’s namespace with: using


  • Unity3d

     You need to import the PhotonUnity3D.dll into your project in
Unity. Simply open a Unity project/scene, open an explorer and drag and
drop the .dll from <sdk>\libs\debug\ into the editor. Again,
import the lib’s namespace with: using ExitGames.Client.Photon;

 你须求导入PhotonUnity3D.dll到品种中,打开Unity 的project/scene,打开财富管理器从<sdk>\libs\debug\ 拖放PhotonUnity3D.dll到editor,导入命名空间using


     Workflow 工作流


     The simplified lifecycle for any multiplayer game looks like this:



  • Connect to server


  • Make RPC calls


  • Receive something


  • Disconnect



     Pretty simple. Let’s have a look at each step, assuming you use C#
and the Lite



  • Connect to server 连接服务器


     Actually, you do a little more than just connect in this step. In



  • Implement the interface IPhotonPeerListener in one of your


  • Create a LitePeer instance with your server’s address

          创制LitePeer 实例和您服务器的地址

  • In your game loop, call Service about 10 times a second


  • Now call Connect to establish the connection. The application
    name should match one in the PhotonServer.config


  • Your implementation if PeerStatusCallback is called when the
    connection is ready or failed


  • The returned status be StatusCode.Connect



     The peer instance provides you with some methods to talk to Photon.
It does not have its own thread. It updates when you
call Service instead. This will keep the connection alive

 peer 实例提供了一些措施去拜访Photon,它从未团结的线程,当你调用服务时它实行立异,并保险着连连


     We assume that Photon is running the “Lite” Application, which it
does by default.



  • Make RPC calls RPC调用


     After connecting, the client can call methods in the Lite
Application just about anytime it needs to. The methods available as
“remote procedure call” are called operations.



     Operation calls are asynchronous and won’t block your game. They
are queued internally until you intently send something by
calling SendOutgoingCommands. There will be a short delay until the
result is received. These results are defined per operation and are not
used at all sometimes.



  • Call OpJoin with any room name to get into a game

          调用OpJoin 能够投入游戏

  • Wait for the
    callback: OperationResult with opCodeLiteOpCode.Join

等待回调带有 opCodeLiteOpCode.Join 的 OperationResult 

  • Send any hashtable with content by calling OpRaiseEvent. Other
    players in the room will receive events.

通过调用OpRaiseEvent发送带有内容的hashtable ,其余这几个房间的玩家也将收到有关的风浪音信。


     Joining a room and raising events in it is provided (server side)
by the Lite Application logic we use in this sample. You can use other
applications and implement your own operations.



  • Receive something 接收数据


     In the previous step you already received an operation result. We
differentiate those from other incoming messages, so called events. Lite
will forward the event you raised to others in a room.



     Receiving events will call IPhotonPeerListener.EventAction.
The evCode will match the one you used in OpRaiseEvent

 调用IPhotonPeerListener.EventAction接到事件,evCode 将与您使用的OpRaiseEvent进展匹配


     The client library will internally queue received packages, so your
game decides when to use them. EventAction is called by your calls
to PhotonPeer.Service.



  • Disconnect 断开连接


     When a client is closed, the best is to disconnect. That’s nice,
but not a must-have as a timeout will disconnect clients that don’t
answer anymore.



  • To close the connection: call Disconnect


  • Check “disconnect” return
    in PeerStatusCallback with statusCodeStatusCode.Disconnect

检查 “disconnect” ,PeerStatusCallback 的重返值为statusCodeStatusCode.Disconnect

  • Now the client can stop calling service


     LitePeer versus PhotonPeer LitePeer与PhotonPeer 


     Aside from the LitePeer, the client libraries also include a
PhotonPeer which could be used. The PhotonPeer has the bare minimum of
API needed for Photon. It is the base for LitePeer, which adds
operations like “Join”, “Leave” and “RaiseEvent”, which are available
with the Lite Application.

 除了LitePeer,客户端还蕴涵了四个PhotonPeer 可以行使,PhotonPeer 对于Photon唯有少数的API,它是LitePeer的底蕴,Lite中LitePeer扩大了“Join”、“Leave”

     Reliable UDP 可靠的UDP


     Under the hood, Photon clients and servers send operations and
events via UDP. This guarantees low overhead, flexibility and
performance but is unreliable by definition.



     Within the UDP packages, Photon uses a thin binary protocol to
enable aggregation, ordering, detection of packet loss and more. It is
based on eNet and used in similar form on client and server.

 在UDP包中,Photon 使用了一个精简的二进制协议来实行联谊、排序、检测数据包不见,它是基于eNet的被用来服务器和客户端


     So called “commands” are used to transfer the payload, such as
operations. On the client side, Photon gives you full control of when
commands are put into a UDP package and send.



     As a result, the API also includes methods that manage the
connection to the server. Basically, there are two “layers”: the
“command layer” and the “operation layer”:

layer” 和 “operation layer”

  • Command layer: manages the communication protocol to establish
    and maintain communication.


  • Operation layer: gives access to rooms, events and custom
    Operations. Client side, methods of this layer are prefixed with

操作层:用于访问房间、事件、自定义操作。在客户端,那层的章程被添加了前缀 “Op”

     Reliable vs. Unreliable 可信对不可信


     With Photon’s underlying protocol, everything that’s sent across
can be made flagged as reliable or unreliable. The operation request is
not changed by this though, only the command that’s used.



www.27111.com,     Photon keeps track of the ordering. Even unreliable commands are
synchronized/sequenced within the order of reliable commands. So an
unreliable command, which was sent after a certain reliable command,
will also be dispatched after the reliable command was dispatched (even
if that command was delayed).

 Photon 保持跟踪,不可靠的一声令下是随着保证的下令举行协同测序,所以1个不可靠的命令,被发送在一个可信赖的通令之后,也将在保障命令被分摊之后再举办分摊。


     Operations and events that are sent as unreliable might get lost.
As example, this is no problem for position updates, which are quickly
replaced. On the server side, Operations that are received unreliable,
should not create a result: The client can not expect that the operation
even reached the server.


     Connection and Timeout 连接与超时


     The client has two rules to define a timeout:



  • Retries: A reliable command is sent multiple times to be
    acknowledged, each time the interval between retries gets longer,
    depending on general rountrip times. If the number of retries
    reaches a limit (in DotNet: SentCountAllowance), this causes a


  • DisconnectTimeout: This defines a maximum number of
    milliseconds, before a reliable command must be answered. This is
    independent of the retry counting. In DotNet, the setting
    is: DisconnectTimeout.



     The settings are described in more detail in the client API




电子邮件地址不会被公开。 必填项已用*标注