建立簡單的Photon服務器(二)
上一篇博文(Photon教程——建立簡單的Photon服務器(一))的地址:https://blog.csdn.net/ultramansail/article/details/102755901
生成庫文件
一、生成解決方案
- 指定解決方案生成的輸出目錄
(1)右擊解決方案,點擊“屬性”
(2)屬性窗口打開後,點擊“生成”,點擊輸出路徑後的瀏覽按鈕,選擇輸出路徑,要記住這個路徑,以後講這個路徑直接用“輸出路徑”表述
2.點擊“生成->生成解決方案”
3.我們發現“輸出路徑/netstandard2.0”目錄多了這些文件(有些版本可能直接在“輸出路徑”目錄)
在Photon目錄創建應用
一、新建應用目錄
1.在Photon根目錄下的“deploy”目錄下新建一個文件夾,命名爲“GameServer”,在“GameServer”目錄下新建文件夾“bin”
2.把“輸出路徑/netstandard2.0”(或“輸出路徑”)目錄下的文件全部拷貝到“Photon根目錄/deploy/GameServer/bin”目錄
二、配置PhotonServer.config文件
1.在“Photon根目錄/deploy/bin_Win64”目錄下找到“PhotonServer.config”文件,打開它
2.在最末尾的</Configuration>前追加一下內容
<!-- Instance settings -->
<GameServer
MaxMessageSize="512000"
MaxQueuedDataPerPeer="512000"
PerPeerMaxReliableDataInTransit="51200"
PerPeerTransmitRateLimitKBSec="256"
PerPeerTransmitRatePeriodMilliseconds="200"
MinimumTimeout="5000"
MaximumTimeout="30000"
DisplayName="Game Server"
>
<!-- 0.0.0.0 opens listeners on all available IPs. Machines with multiple IPs should define the correct one here. -->
<!-- Port 5055 is Photon's default for UDP connections. -->
<UDPListeners>
<UDPListener
IPAddress="0.0.0.0"
Port="5055"
OverrideApplication="GameServer">
</UDPListener>
</UDPListeners>
<!-- 0.0.0.0 opens listeners on all available IPs. Machines with multiple IPs should define the correct one here. -->
<!-- Port 4530 is Photon's default for TCP connecttions. -->
<!-- A Policy application is defined in case that policy requests are sent to this listener (known bug of some some flash clients) -->
<TCPListeners>
<TCPListener
IPAddress="0.0.0.0"
Port="4530"
PolicyFile="Policy\assets\socket-policy.xml"
InactivityTimeout="10000"
OverrideApplication="GameServer"
>
</TCPListener>
</TCPListeners>
<!-- Policy request listener for Unity and Flash (port 843) and Silverlight (port 943) -->
<PolicyFileListeners>
<!-- multiple Listeners allowed for different ports -->
<PolicyFileListener
IPAddress="0.0.0.0"
Port="843"
PolicyFile="Policy\assets\socket-policy.xml"
InactivityTimeout="10000">
</PolicyFileListener>
<PolicyFileListener
IPAddress="0.0.0.0"
Port="943"
PolicyFile="Policy\assets\socket-policy-silverlight.xml"
InactivityTimeout="10000">
</PolicyFileListener>
</PolicyFileListeners>
<!-- WebSocket (and Flash-Fallback) compatible listener -->
<WebSocketListeners>
<WebSocketListener
IPAddress="0.0.0.0"
Port="9090"
DisableNagle="true"
InactivityTimeout="10000"
OverrideApplication="GameServer">
</WebSocketListener>
</WebSocketListeners>
<!-- Defines the Photon Runtime Assembly to use. -->
<Runtime
Assembly="PhotonHostRuntime, Culture=neutral"
Type="PhotonHostRuntime.PhotonDomainManager"
UnhandledExceptionPolicy="Ignore">
</Runtime>
<!-- Defines which applications are loaded on start and which of them is used by default. Make sure the default application is defined. -->
<!-- Application-folders must be located in the same folder as the bin_win32 folders. The BaseDirectory must include a "bin" folder. -->
<Applications Default="GameServer">
<!-- Game Server Application -->
<Application
Name="GameServer"
BaseDirectory="GameServer"
Assembly="GameServer"
Type="GameServer.GameServer"
ForceAutoRestart="true"
WatchFiles="dll;config"
ExcludeFiles="log4net.config">
</Application>
<!-- CounterPublisher Application -->
<Application
Name="CounterPublisher"
BaseDirectory="CounterPublisher"
Assembly="CounterPublisher"
Type="Photon.CounterPublisher.Application"
ForceAutoRestart="true"
WatchFiles="dll;config"
ExcludeFiles="log4net.config">
</Application>
</Applications>
</GameServer>
注Application代碼塊中,Name是服務的名稱(應用的名稱),BaseDirectory是應用相對於“Photon根目錄/deploy”的路徑,Assembly是程序集,是主類(繼承自ApplicationBase的類)的名稱,Type是類的類型,一般爲“命名空間.類名”
三、開啓服務器
1.打開主程序“Phton根目錄/deploy/bin_Win64/PhotonControl.exe”
2.右擊PhotonControl的後臺圖標,點擊“Game Instance->Start as application”,啓動服務(如果服務啓動不了,請檢查配置文件),退出應用則點擊“Stop application”
下一篇博文(Photon教程——使用log4net插件在Photon中打印log)的地址:https://blog.csdn.net/ultramansail/article/details/102756662