Base Applications 基本應用程序
The Photon Server SDK includes several applications that should provide a good starting point for your own development. What each SDK does and for which game-style it might be a useful basis is described below.
以下是Photon服務器SDk包含的內置應用程序,可以作為你的應用的開始點。
Lite
The Lite Application is probably the most often referenced application. It implements the basic framework for room based games in which players gets together to play a match in a small group. Each room reflects a game and is identified by its name. Anyone connected can join and leave without restriction. Inside a room any client can raise events to send data across to the others. Properties can be set for rooms and actors to keep certain values available for everyone joining.
Lite 是一個最常引用的應用,它實現了一個多玩家一起競賽的房間游戲的基本框架,通過名稱確定每個房間,一個房間就是一個游戲,任何人都可以不受限制的加入或離開,在房間內任何客戶端都可以觸發事件去發送數據給別人,可以為房間和玩家設置屬性來確保進入的玩家有準確可用的值
Games, which don’t need an authoritative server, can be built on top of Lite without modifications.
所有游戲,不需要一個權威的服務器,可以建立在Lite之上并且不需要修改它
This application can easily be extended with server-side logic per room. Matchmaking could group players in rooms, depending on your game’s requirements.
這個應用可以容易的擴展服務器端的邏輯,根據你的游戲需求匹配一組玩家到房間里
Lite Lobby
The Lite Lobby Application is an example of how to build on top of Lite and extend its functionality. Lite Lobby adds new types of rooms: Lobbies. These won’t send join/leave events but list currently used room names. The player (or client code) can easily chose from running games. The count of users in a room is provided additionally.
Lite Lobby是一個在Lite之上建立并擴展功能的例子,它添加了新的房間類型:大廳。這里不會發送加入或離開事件,只是當前可用的房間名稱列表。玩家可以很容易的選擇正在進行的游戲,房間中玩家的數量是可供增加的
This application adds “manual matchmaking” to Lite and could also be a basis for your game.
這個應用增加了手動匹配
MMO
The MMO Demo Application is a good solution for games where all players share a large world. It provides interest management and the most common base classes for items, actors, properties, and more.
MMO樣例程序是一個為玩家們分享一個大型世界的游戲解決方案,它提供了興趣管理和最常見的類型,比如物品、玩家、屬性等等
Games with a shared world contain more game-specific logic on the server side typically, so this application should be understood as a sound starting point.
這游戲是一個在服務端包含了更多的游戲邏輯的分享的世界,這個應用被認為是一個合理的開始點
Policy
The Policy Application runs on Photon to send the crossdomain.xml to web player platforms (e.g. Unity Web Player). Flash and Silverlight request an authorization before they contact a server.
Policy應用運行在Photon上用于發送crossdomain.xml到web player平臺。Flash 和 Silverlight在連接一個服務器之前需要請求一個授權
It has its own page in the DevNet: Policy Application
它有自己的頁面在DevNet上
Counter Publisher
This application reads and forwards local PerfMon counters of Photon Core to the Dashboard. It does not interfere with other applications, and clients should not connect to it.
這個應用讀取本地的PerfMon計數器到Dashboard。它不會影響其他應用程序,客戶端也不要去連接它
Basic Concepts 基本概念
The following article will show you the important basic concepts for Photon.
以下是要告訴你的Photon重要基本概念
Applications 應用程序
An Application is the server side logic for a game. All features of a game (e.g. remote procedure calls, data storing, etc.) are implemented in a Photon application. The C# source is compiled and the resulting assemblies are loaded by Photons native core. To setup applications and to define start parameters the Photon Core uses configuration files.一個應用既是一個服務端的游戲邏輯,一個游戲的所有特征是在Photon應用中被實現的。由C#編寫的源碼被編譯成程序集并加載到Photons native core。部署應用并且在Photon配置文件中定義參數。Usually, all logics of a game are provided in a single application. Photon is still able to run several applications at the same time. Each application can have a different task. For example, a separate application can be made to send out policy files for web-based clients. By running a separate Policy Application next to your game logic you can add functionality.通常,一個游戲的所有邏輯是由一個應用程序提供的,Photon 是可以同時運行多個應用程序,每個應用程序可以有不同的任務。比如,一個獨立的應用程序可以被用于為基于Web的客戶端發送policy文件,通過運行一個獨立的Policy應用程序為你的游戲邏輯添加功能A client chooses the application it wants to use by simply providing the application’s name on connect.一個客戶端在連接的時候需要使用應用的名字去選擇應用程序
Game Logic 游戲邏輯
The game logic defines how a client can interact with the server. It implements operations, events, and anything that the server does by itself.游戲邏輯定義了客戶端如何與服務器進行交互。它實現了操作、事件和其他服務器想做的事情A good basis for room based games is provided as “Lite” Application , found in the SDK folder src-server/Lite. It does not know (your) game’s logic (yet), but provides rooms where players can communicate and interact easily. The application “Lite Lobby” extends Lite with lists of rooms if you want your users to select a room manually.Lite是一個很好的基于房間的游戲基礎應用,src-server/Lite中可以找到它,它不知道你的游戲邏輯,但是提供了房間,玩家可以輕松的進行交流與互動。Lite Lobby擴展了Lite,提供了房間列表,以便于用戶可以手動選擇房間If your game is going to be a single, huge world, the MMO Demo Application is a good basis for it. This application handles interest management for your clients and provides classes for items, properties, actors and more.如果你的游戲是一個獨立的巨大的世界,那MMO是一個很好的基礎應用,這個應用為你的客戶端提供了興趣管理和一些類型,例如商品、屬性、玩家等等。Alternatively any game logic can be developed directly on top of the C# framework. The entry point for this is the application class, defined in the Photon.Socketserver.dll.或者任何游戲的邏輯都可以在C# framework之上進行開發,這程序的入口必須定義在Photon.Socketserver.dll
Operations 操作
An operation is Photon’s equivalent to a remote procedure call. Photon clients use operation calls for anything they want to get done.一個操作相當于是一次遠程過程調用(RPC)。Photon客戶端使用操作調用進行他們想要做的事情Operations and all of their parameters are defined in the server-side application as needed. Clients can call any operation by setting up a hashtable with keys and values fitting the operation’s conventions. The client and server frameworks take care of serialization, transfer and deserialization.操作和屬性是被定義在服務端的應用程序中的。客戶端可以調用任意操作,只要通過設置一個hashtable 的鍵和值來制定該操作的合約即可,客戶端和服務端的frameworks負責序列化、傳遞和反序列化Each operation can also provide a result. This is one way to provide a client with requested data. Of course the result can be skipped, which saves bandwidth.每個操作也可以提供一個結果。這是一個提供給客戶端請求數據的方法,當然結果是可以被跳過的,跳過可以節省帶寬流量Operation calls and results are a thing between one client and the server. The other clients won’t know about these.操作的調用和結果是一個客戶端和服務器之間發生的,其他客戶端是無法得知。
Events 事件
Photon Events are messages for clients. Each event is typed by a byte code and carries game updates. The Lite Application defines several events but it’s possible to define custom events purely on the client side.Photon事件是對客戶端的消息,每個事件的類型是一個byte代碼,Lite定義了許多的事件,也可以在客戶端定義通用的事件Unlike operation results, a received event is most likely caused another client’s operation call. This means: Events might arrive anytime. Lite sends events when someone joins or leaves a room.不像操作結果,一個接受到的事件最有可能觸發其他客戶端的操作調用,這意味著,事件可能隨時發生,Lite應用中當某個玩家加入和離開房間時會發送事件The Operation RaiseEvent (in Lite) makes events truly universal: Any client can create new events by putting together a hashtable with the data and applying a code on sending it. Game data can be sent without any need to change the server.這個RaiseEvent操作使得事件真正的通用:任意客戶端可以創建一個裝有數據和應用代碼的hashtable的新的事件進行發送,游戲數據可以被發送無需去改變服務器Of course, for more elaborate server side reaction to events, custom operations can be defined which check event data, compile it or create other events.當然,對于更為復雜的服務器端事件的反應,通用操作可以被定義為檢查、編譯事件數據或創建其他事件
Connections and Timeouts 連接與超時
Unlike plain UDP, Photon’s reliable UDP protocol establishes a connection between server and clients: Commands within a UDP package have sequence numbers and a flag if they are reliable. If so, the receiving end has to acknowledge the command. Reliable commands are repeated in short intervals until an acknowledgement arrives. If it does not arrive, the connection is timed out.不像常規的UDP,Photon使用的是可靠的UDP協議建立客戶端與服務端的連接:命令在一個UDP包中,其中包含序列化的數字和一個可靠性標志,這樣接收端才能識別這個命令,可靠的命令是在很短的時間間隔內重復直到被確認,如果不被確認到,則連接超時Both sides monitor this connection independently from their perspective. Both sides have their rules to decide if the other is still available.兩端監控連接都是獨立的,兩端還可以定義自己的規則If a timeouts is detected, a disconnect happens on that side of the connection. As we think the other side does not respond anymore, no message is sent to it. This is why timeout disconnects are one sided and not synchronous.如果一個超時被檢測到,就會斷開連接,這時我們認為另一邊未響應,沒有信息可以發送給它,這就是為什么超時斷開是發生在一側并且是不同步的
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.
在客戶端,Photon支持多樣的平臺,使用C,C#,Flash進行編程的方式是不同的,但是基本的工作流是相似的。在這文檔中我們嘗試去解釋它的概念和背景,而語言的細節部分需要查閱每個語言平臺的參考文檔。
Each Photon Client SDK comes with a fitting reference documentation for its platform and language.
每一個客戶端SDk都帶有相關平臺的參考文檔。
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 ExitGames.Client.Photon;
在項目中引用PhotonDotNet.dll,引用命名空間using ExitGames.Client.Photon
- 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 ExitGames.Client.Photon;
Workflow 工作流
The simplified lifecycle for any multiplayer game looks like this:
多人游戲的簡化生命周期如下:
- Connect to server
連接服務器
- Make RPC calls
RPC調用
- Receive something
接收數據
- Disconnect
斷開連接
很簡單,讓我們來看看每一個步驟,以Lite為例。
- Connect to server 連接服務器
Actually, you do a little more than just connect in this step. In short:
事實上,你做的不只是連接而已:
- Implement the interface IPhotonPeerListener in one of your classes
在你的類中實現接口IPhotonPeerListener
- Create a LitePeer instance with your server’s address
創建LitePeer 實例和你服務器的地址
- In your game loop, call Service about 10 times a second
在你的游戲循環中大約10秒調用一次服務
- Now call Connect to establish the connection. The application name should match one in the PhotonServer.config
現在建立連接,這應用程序的名字要與PhotonServer.config中的匹配
- Your implementation if PeerStatusCallback is called when the connection is ready or failed
你要實現的是當連接是未連接的時候調用PeerStatusCallback
- The returned status be StatusCode.Connect
返回的狀態是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.
我們假設Photon運行著Lite,以下是默認情況。
- 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.
連接后,客戶端可以再任何時候去調用Lite應用的方法,這樣的遠程過程調用被稱為操作
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.
操作調用是異步的,并且不會阻礙你的游戲。他們是在內部排隊的直到你需要發送他們的時候通過SendOutgoingCommands發送。收到結果只需要很短暫的延遲時間,這些結果是被定義為操作并且不是所有的時間都被使用的。
- Call OpJoin with any room name to get into a game
調用OpJoin 可以加入游戲
- Wait for the callback: OperationResult with opCode: LiteOpCode.Join
等待回調帶有 opCode: LiteOpCode.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.
這是一個按照Lite應用的邏輯加入房間并觸發事件的例子,你可以使用其他的應用并且實現你自己的操作
- 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.
在前面的步驟,你已經接收到了操作的結果,我區別于來自其他地方的信息,所以稱之為事件,Lite將發送這事件觸發到房間中的其他人。
調用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.
這客戶端將接收到的數據包進行內部排隊,由你的游戲決定何時使用它們,通過調用PhotonPeer.Service來調用EventAction
- 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
關閉連接:調用Disconnect
- Check “disconnect” return in PeerStatusCallback with statusCode: StatusCode.Disconnect
檢查 “disconnect” ,PeerStatusCallback 的返回值為statusCode: StatusCode.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” 、“RaiseEvent”等。
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.
在底層,Photon客戶端和服務器通過UDP發送操作和事件的,這保證了低開銷、靈活性和性能但是被定義為不可靠的。
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.
所謂的“commands”是用于傳遞這負載的,例如操作。在客戶端,由Photon控制命令以UDP包的形式進行發送
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”:
因此,API還包括管理連接服務器的方法,基本上,他們是由兩個層組成:“command 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”.
操作層:用于訪問房間、事件、自定義操作。在客戶端,這層的方法被加上了前綴 “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.
Photon的底層協議,可以被標記為可靠或不可靠,僅僅在命令被使用的時候操作請求是不可更改的。
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 保持跟蹤,不可靠的命令是隨著可靠的命令進行同步測序,所以一個不可靠的命令,被發送在一個可靠的命令之后,也將在可靠命令被分派之后再進行分派。
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 disconnect.
重試:一個可靠的命令將會被發送多次以用作確認,每次重試的時間間隔變長,根據統一的區域時間定義,如果重試次數達到一個極限,將會斷開連接。
- 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.
斷開超時:這定義了一個可靠命令必須答復的時間間隔的最大毫秒值,這是獨立于重試計數的,在DotNet中設置為DisconnectTimeout
The settings are described in more detail in the client API documentation.
這詳細的信息請閱覽客戶端文檔。
Setup and Config 設置與配置
This chapter explains how files and folders are organized for the Photon Server and how things are setup. Everything needed is in the deploy folder.
這章解釋了在服務器上文件和文件夾是如何被組織和配置的。
Content 內容
-
- Organization of Server and Applications 組織服務器與應用程序
- Configuration: PhotonServer.config 配置PhotonServer.config
- The Application Node 應用程序節點
- UDPListeners and TCPListeners Nodes UDP監聽和TCP監聽節點
- TCPSilverlightListeners and TCPFlashListeners Nodes TCP的Silverlight和Flash的監聽節點
- Timeout Settings 超時設置
- Send Delay and Ack Delay 發送延遲和Ack延遲
Organization of Server and Applications 組織服務器與應用程序
There are four versions of Photon in the folders: “bin_Win32”, “bin_x64”, “bin_Win32_xp” and “bin_win64_xp”. We refer to these as binaries-folders.
在文件夾中這有不同版本的Photon:“bin_Win32”, “bin_x64”, “bin_Win32_xp” and “bin_win64_xp”,我選擇需要使用的那個二進制文件夾。
Photon requires a separate folder next to the binaries-folder per application (e.g. “Lite” in the deploy folder). The assemblies must be in a “bin” subfolder (e.g. Lite/bin).
Photon需要獨立的文件夾去存放應用程序,程序集必須放在文件夾內的Bin目錄下。
.jpg)
The following folders in the Server SDK deploy folder are applications: Lite, LiteLobby, MMO, CounterPublisher, Policy Applications are setup in Photon’s config file, as explained below.
在服務器SDk deploy 文件夾下的應用程序有: Lite, LiteLobby, MMO, CounterPublisher, Policy Applications,被配置在Photon的配置文件中。
The bin_tools folder currently contains useful tools:
bin_tools文件夾中有以下可用的工具:
- Baretail: Our favorite log viewer in the free edition. It is used by PhotonControl to view the latest logs.
日志查看器
- Photon Dashboard: The service to collect and concentrate Dashboard Counters and display them on a webpage.
儀表板計數器
- Perfmon: Contains a list of PerfMon counters used when you setup counter logging to a file. This is explained under “Administration”.
性能監視器
- Stardust: A commandline testclient that can be used to get some load on a machine. This is shown in Photon in 5 Minutes
命令行測試客戶端,可以用來測試機器的負載
Configuration: PhotonServer.config 配置PhotonServer.config
The main configuration file for Photon is the PhotonServer.config. An identical copy is located in each binaries-folder in the SDK. It is used to setup applications, listeners for IPs and performance specific values. It does not contain config values for the game logic.
PhotonServer.config是Photon的主配置文件,在每個二進制文件夾中,它是用來配置應用程序,監聽器和性能值。他不能用來配置游戲邏輯的值。
The default values make sure Photon scales nicely on more cores but does not overwhelm a regular machine. In general performance tweaks are not needed.
這默認值保證了Photon的兼容性,一般情況下性能不需要調整
The following settings are most commonly used. More options are described in the “photon-configuration.pdf”, located in the Server SDK.
以下是最常用的設置項,更多的設置請參看“photon-configuration.pdf”,在本地服務器的SDK中。
The Application Node 應用程序節點
The config file defines which applications Photon should load on startup. In the “Applications” node, several “Application” entries can be added.
配置文件定義了Photon將運行哪些應用程序,在 “Applications” 節點中為每個應用程序添加一個 “Application”節點。
< Applications Default = "Lite" > <!-- Lite Application --> < Application Name = "Lite" BaseDirectory = "Lite\Lite" Assembly = "Lite" Type = "Lite.LiteApplication" EnableAutoRestart = "true" WatchFiles = "dll;config" ExcludeFiles = "log4net.config" > </ Application > </ Applications > |
Each application is assigned a name by which the clients reference it on connect (compare: Photon Client Workflow ).
每個應用的名字是作為客戶端連接的依據。
The BaseDirectory defines the folder in which an application resides. It does not name the “\bin” folder but expects it by convention. The Assembly names the .dll of an application and “Type its “main” class (which derives from Photon.SocketServer.Application).
BaseDirectory 定義了應用程序所在的文件夾,不能命名為 “\bin”,但是要包含它。Assembly 是程序集的名稱,Type 是主類的名稱(繼承于Photon.SocketServer.Application)
The setting EnableAutoRestart tells Photon to start a shadow copy of the loaded application. This allows developers to replace the files without locking issues, making development more convenient. Photon will automatically start a new instance of an application 10 seconds after files are changed. WatchFiles and ExcludeFiles refines the list of files that trigger a restart. Clients that connected to a previous shadow copy will stay in it. New connects will use the new logic.
設置EnableAutoRestart 可以讓Photon加載應用的副本。這將允許開發人員在替換文件時不用擔心文件被鎖住的問題,使的開發更加的方便。Photon將在文件更改后10秒重新啟動一個新的應用實例。WatchFiles 和 ExcludeFiles 在觸發重啟時改進文件列表,連接之前副本的客戶將繼續使用舊副本,新的連接將創建新的游戲邏輯。
To load multiple applications, simply add more application nodes (with unique name). One of them can be made the default application by using its name (“Lite” in the example). The default app is the fallback for clients that try to connect to an unknown application.
加載多個應用程序,只需加入新的application 節點(名字必須是唯一的)。可以通過應用名稱來設置應用程序為默認應用。當客戶端嘗試連接一個未知的應用時將連接到默認應用程序。
Applications that are not setup in the PhotonServer.config won’t be loaded and don’t need to be deployed. When an application is in the config but the files are missing Photon won’t start and name the issue in the logs.
當 PhotonServer.config中的某個應用程序文件丟失時,該應用程序將不被加載和部署,Photon服務將不會啟動,該問題將記錄在日志中。
UDPListeners and TCPListeners Nodes UDP監聽和TCP監聽節點
These configure UDP and TCP endpoints on your machine respectively. You can use either (e.g. only UDP) or both.
在你的機器上配置UDP和TCP的端口,你可以使用其中的一種或兩種。
The default IP 0.0.0.0 makes Phonton listen on any locally available IP. By replacing the wildcard IP, Photon will open only specific IPs and ports. Multiple UDPListener and TCPListener nodes can be defined, opening several IP/port combinations.
默認IP是0.0.0.0,這使得Photon將監聽所有的本地可用的IP。通過替換IP通配符,Photon將打開指定的IP和端口。可以定義多個UDPListener 和 TCPListener 節點來打開多組IP與端口組合。
Per UDPListener and TCPListener node, you can setup an OverrideApplication or DefaultApplication. Override means: any client that connects to this port will end up in the application named, no matter what the client connects to. Default is a fallback, in case the application named by a client is not found.
每個UDPListener 和 TCPListener 節點,你可以設置一個OverrideApplication 或 DefaultApplication。Override 的意義是:任意連接該端口的客戶端無論它連接到什么都將在已命名的應用中結束,Default 是備用的,用在客戶端找不到已命名的應用程序。
<
UDPListeners
>
<
UDPListener
IPAddress
=
"0.0.0.0"
Port
=
"5055"
OverrideApplication
=
"Master"
>
</
UDPListener
>
<
UDPListener
IPAddress
=
"0.0.0.0"
Port
=
"5056"
OverrideApplication
=
"Game1"
>
</
UDPListener
>
</
UDPListeners
>
Note: If you are using a license that's bound to an IP you need to set this IP in the config.
注:如果你是使用一個綁定了IP地址的許可證,你需要將這個IP地址配置到配置文件中。
TCPSilverlightListeners and TCPFlashListeners Nodes TCP的Silverlight和Flash的監聽節點
Could be removed but are needed when you create Silverlight or Flash games respectively. Both client-side plugins require a server to respond with a “policy file” (unless the website is on the same domain as Photon).
可以移除該配置,單當你需要創建Silverlight 或 Flash 游戲時是需要的,客戶端請求服務器響應一個policy文件(除非網站在同一個域內)
Timeout Settings 超時設置
Two values in the instance node describe how the server times out unresponsive UDP clients: MinimumTimeout and MaximumTimeout.
有兩個節點來描述服務器超時:MinimumTimeout 和 MaximumTimeout
<
Instance1
EnablePerformanceCounters
=
"true"
DataSendingDelayMilliseconds
=
"50"
AckSendingDelayMilliseconds
=
"50"
MinimumTimeout
=
"5000"
MaximumTimeout="30000”>
A peer connected with UDP has MinimumTimeout milliseconds to respond before it can be disconnected. The actual time until disconnect, is determined dynamically per peer based on the RTT history. Previously good RTTs will disconnect faster.
在連接斷開之前UDP通信有MinimumTimeout 的時間用于響應,斷開的實際時間是動態的基于RTT歷史的。
TCP connections have a separate InactivityTimeout setting in the nodes TCPListener and TCPPolicyListener (also in the PhotonServer.config). We set those to 5 seconds (5000ms). If no request arrives in this time, the connection will be timed out and closed. Clients will also regularly Ping the server, to avoid this. Clients don’t timeout for TCP.
TCP連接有一個獨立的配置項InactivityTimeout 在TCPListener 和 TCPPolicyListener 節點,我設置為5000ms,如果請求沒有在這個時間間隔內到達,連接將會超時并關閉。客戶端將定期Ping服務器以避免這樣的超時。
Keep in mind that a client independently monitors a connection and might time it out as well. Both sides should have similar timeouts, fitting your game.
保持客戶端獨立的監控連接和時間,使雙方將有相似的超時,以適應你的游戲
Send Delay and Ack Delay 發送延遲和Ack延遲
The attributes DataSendingDelayMilliseconds and AckSendingDelayMilliseconds represent a tradeoff between performance and minimal response times. This delay directly adds some lag to reduce the bandwidth usage: the wait allows the server to aggregate commands and send them in one package. The send delay is triggered when the server sends anything, the ack delay by incoming reliable data.
屬性DataSendingDelayMilliseconds 和 AckSendingDelayMilliseconds 代表了性能與最小響應時間之間的權衡。這延遲減小了帶寬流量的使用:這等待允許服務器識別命令并用一個數據包發送他們。當服務器進行發送時將觸發這個發送延遲,ack延遲是通過傳入可靠的數據。
As you can see above, the default values are 50ms each. We found this to be a good value but it causes a \~50ms roundtrip time, even if client and server run on the same machine.
正如你所看到的,這默認值是50ms。我們發現它是一個很好的設置,在50ms內進行一次往返,即使當客戶端和服務器在同一臺機器上也是如此。
Depending on your game, you should load test with different values. A delay of 0 is a special case that skips usage of timers, so avoid low delays < 10.
你可以根據你的游戲,加載測試不同的值。0ms是一個特殊值用于跳過延遲,盡量避免延遲小于10ms
Photon Control Photon控制器
Photon Control is your one-stop, control UI for Photon. Starting PhotonControl.exe doesn’t open a window, doesn’t start the server but adds an icon to the tray bar.A gray icon shows that Photon is not running. When any Photon Server is process running, the icon turns blue.
Photon Control是一個針對Photon的一站式的可視化的控制軟件,打開PhotonControl.exe不會出現windows窗口,不會啟動服務,但會增加一個系統托盤,灰色的圖標表示Photon不在運行,而藍色的圖標表示Photon正在運行。
Content 內容
-
- Overview 概述
- Running Photon 運行Photon
- Moving Photon 移動Photon
- Changing the “LoadBalancing IP Config” Path 改變“LoadBalancing IP Config”的路徑
- Logs 日志
- Counters 計數器
- PerfMon Counters 性能監視器
- Dashboard Counters 儀表板計數器
- Dashboard 儀表板
- Troubleshooting 故障診斷
- Dump File Setup 轉儲文件設置
Overview 概述
Click the icon to open the menu. It allows you to:
點擊系統托盤去打開菜單:
- Start and stop Photon.
啟動和停止Photon
- Install, start and stop Photon services.
初始化,啟動,停止 Photon服務
- Change the game server config for LoadBalancing (MyCloud).
改變游戲服務器為LoadBalancing(MyCloud)
- Setup and open Photon’s Performance Monitor (PerfMon) Counters.
設置并打開Photon的性能監視器
- Open the log files.
打開日志文件
- Open working path in Explorer.
在資源管理器中打開工作路徑
- Verify you are using the latest version of Photon.
檢查更新
Admin rights are required when you start Photon Control. This allows us to make an entry in the Windows Firewall and most importantly you can now add or remove services for Photon.On start, Photon Control reads your license to let you verify how long it is valid and checks if you use the latest version of Photon, shown in the “Photon Control” menu.The “Autostart Photon Control” option starts Photon Control when you login to Windows. This can be handy when you access a remote machine and can use “Explore Working Path” to spot Photon’s files.If the icon is not visible, click the tiny triangle and drag and drop the Photon Control icon from the popup back to the tray.
需要管理員權限才能啟動Photon Control,配置防火墻使Photon服務可用。當Photon Control啟動時會讀取許可證來設置Photon的版本,顯示在Photon Control的菜單上,設置“Autostart Photon Control” 選項可以在登錄系統時自動啟動Photon Control。這是非常方便的去遠程訪問一個機器,并且可以通過 “Explore Working Path”找到Photon的文件,如果圖標不可見,點擊小三角拖放該圖標到托盤上。
Running Photon 運行Photon
By default, two separate Photon configurations (also called “Instances”) are available. Each starts a combination of server applications and used ports. The “Default” instance is running Lite, LiteLobby, MMO and the Policy Application. Starting instance “LoadBalancing (MyCloud)” will run a Master Server and two Game Servers, which is a minimum Photon Cloud compatible setup.
默認情況下,有兩種獨立的Photon配置是可用的,每個可以啟動一個服務器應用程序和使用所需的端口,Default實例運行的是Lite、 LiteLobby、MMO 和 Policy Application。LoadBalancing (MyCloud) 實例運行的是一個主服務器和兩個游戲服務器,這是一個最小的 Photon Cloud 兼容設置。
On a public server, Photon should run as service. This requires three steps in Photon Control:
在一個公共服務器上,Photon作為服務運行,需要以下三個步驟:
- Install the Photon service
初始化Photon服務
- Install the PerfMon Counters (they might prove useful)
初始化性能監視器
- Start Photon as service
啟動Photon作為服務
.jpg)
The PerfMon Counters are not exactly a requirement to run but they can’t be enabled while Photon is running, so it makes sense to set them up first.Running Photon as application is an alternative for local development. When you log off, Photon will be shut down.
PerfMon Counters不是服務運行的必須條件,但是當Photon正在運行的時候他們不能被啟用,所以要一開始就設置它,運行Photon為應用程序是本地開發的一種選擇,當你注銷時,Photon就會被關閉。
Moving Photon 移動Photon
Before you move Photon from one folder to another, you should make sure to remove all services and also Photon Control autostart. Install again at the new location.
在你移動Photon從一個文件夾到另一個之前,你需要確認移除所有的服務,并且Photon Control是自動啟動的,然后在新的地方再次初始化。
Changing the “LoadBalancing IP Config” Path 更改“LoadBalancing IP Config” 的路徑
While Photon Control can’t be modified extensively, some important settings can be found in PhotonControl.exe.config. The “GameServerConfigPaths” setting is the one you might need when your project is based off LoadBalancing but renamed.The GameServerConfigPaths is a list of ‘;’-separated paths, relative to the folder of PhotonControl.exe.
Photon Control不能被廣泛的修改,一些重要的設置可以在PhotonControl.exe.config里找到。當你的項目是基于LoadBalancing,但不是重命名的,“GameServerConfigPaths” 設置項可能是你需要的,GameServerConfigPaths 是一個以 ‘;’間隔的地址路徑列表,路徑相對于PhotonControl.exe所在的文件夾。
Logs 日志
Photon is logging essential information (state, exceptions, etc.) to several log files. Click on “Open Logs” to show all logs that Photon used in the past 12 hours. You can open more files as needed, of course.
Photon會記錄一些必要的信息到服務器的日志文件中。點擊 “Open Logs” 可以看到所有過去12小時內的日志,當然,需要的話你可以打開更多的文件。
There are two “log” folders:
以下是2個日志文件夾:
- All application logs are in the deploy/log folder. Anything that is logged by your business logic goes into a fitting file in deploy/log.
所有應用程序的日志是在deploy/log folder。任何的業務邏輯的記錄都會填充到這個文件夾下的一個文件中。
- The server core’s log folder is where your running executable is (e.g. bin_win32/log). They contain anything instance and CLR (dotnet runtime) related.
服務器的核心日志文件夾在你運行的二進制目錄之下的log文件夾內,其中包含了所有相關的實例和CLR
We use Log4Net in the logic layer. It can be configured extensively and proved very useful. Learn more about Log4Net here .
我們可以在邏輯層內使用Log4Net。它可以進行廣泛的配置并已證明它是非常的有用。
Counters 計數器
Photon keeps track of several essential values as support for performance- and error-analysis. These are published in two separate sets of Counters: “PerfMon Counters” and “Dashboard Counters”.
Photon持續跟蹤一些基本的值用作性能和錯誤分析。以下是兩個已公布的獨立的計數器:“PerfMon Counters” 和 “Dashboard Counters”。
PerfMon Counters 性能監視器
The PerfMon Counters are key values from the Photon Core. They track values like connected peers, package count, reliable UDP usage, bandwidth and much more. These Counters cannot be changed by the developer and are accessed by PerfMon. PerfMon is a GUI to create those performance graphs and is already installed with Windows.If PerfMon Counters should be logged over a longer time (and without running the GUI), Photon Control can setup and start logging to a file. Under “PerfMon Counters”, click “Create Logging Set” and “Start Logging”. The logs should end up under C:\PerfLogs\Admin\photon_perf_log_<date>.blg
PerfMon Counters的值來自Photon Core。他們跟蹤一些值,例如連接用戶,包計數,可靠UDP的使用,帶寬流量。這些計數器不能通過開發和訪問PerfMon而被改變。PerfMon 是一個已經安裝在windows上的圖形化的工具用來創建一些性能圖形。如果在一個較長的時間范圍內PerfMon計數器被記錄,Photon Control可能會設置和記錄信息到文件里。 在“PerfMon Counters”里可以點擊“Create Logging Set” 和“Start Logging”進行配置。日志放置在C:\PerfLogs\Admin\photon_perf_log_<date>.blg。
Dashboard Counters 儀表板計數器
The Dashboard Counters track values within the business logic and can be extended as needed.
儀表板計數器是在業務邏輯中跟蹤數值的。
Dashboard 儀表板
The Dashboard aggregates counter values and generates graphs for a website to monitor them.The Dashboard itself can be installed as service while Photon is already running. Which Counter Data an application publishes (if at all), depends on the application’s setup. Lite has several pre-defined Counters ready to use.
儀表板收集計數器的值,并且在Web上生成圖形用于監控它們。當Photon運行的時候儀表板可以作為服務進行初始化。應用程序的計數器數據的發布取決于應用程序里的定義。Lite里包含有多個預定義的計數器可以使用。
Troubleshooting 故障診斷
If Photon does not behave as expected, always have a look at the logs.
如果Photon不是像預期的那樣,可以看一下日志。
These are the most common pitfalls you should check as well.
以下是最常見的錯誤,你需要檢查一下
- Missing DotNet 3.5: In this case, Photon can’t start. Don’t mix this up with the CLR Version. The 2.0 CLR version is also used by DotNet 3.5.
缺少DotNet運行環境
- Application missing: If Photon does not find one of the configured applications, it can’t start. Check the configuration against deployed folders.
缺少已配置的應用程序文件
- Build not up to date: Switching to a new server SDK, you should always re-build your applications, referencing the assemblies from the libs folder. Otherwise they might be incompatible.
應用引用的SDK版本與服務器不一致。
- Firewall: If Photon is running but not accessible from another machine, check the Firewalls. Newer Windows versions have roles and rights and your hoster most likely used hardware firewalls.
防火墻阻止了
- Lag: By default, the roundtrip time is about 50ms, even locally. This depends on a setting, explained on the setup page. Read: Send Delay and Ack Delay
延遲超過設置的值,默認為50ms
Dump File Setup 轉儲文件設置
If a server crashes and the reason for it is not found in the logs, Photon can be configured to create dump files. These reflect the state and memory of the crash and are invaluable to debug these cases.To enable the feature, you need to edit your PhotonServer.config. Set the instance-attribute “ProduceDumps” to true and restart the server.
如果服務器崩潰了,日志中未能找到相關信息。Photon可以配置為轉儲文件。那些反應了狀態和內存的信息是在調試中非常有用的。啟用這個特性,你需要去編輯PhotonServer.config。設置“ProduceDumps”為True,并重啟服務器。
It might look like this example:
以下是一個例子:
<
Default
EnablePerformanceCounters
=
"true"
DataSendingDelayMilliseconds
=
"50"
AckSendingDelayMilliseconds
=
"50"
MinimumTimeout
=
"5000"
MaximumTimeout
=
"30000"
ProduceDumps
=
"true"
>
This will write up to 10 “full” dump files. Once a dump file is written, you can zip it with the logs and mail it to us with a description of the issue. In most cases, we will get in touch with you to get more information and solve the case.
這將寫入完整的轉儲文件。一旦轉儲文件被寫入,你就可以壓縮它發送郵件給我們,在大多數情況下,我們會為你解答。