卜若的程式碼筆記-photon系列-第一章:環境的安裝
1.從官網上下載並且安裝
2.安裝後,進入到你的安裝路徑
3.進入deploy將你的許可證放到裡面
4.開啟visualstudio
建立一個類庫
5.新增引用:
ExitGamesLibs.dll
Photon.SocketServer.dll
PhotonHostRuntimeInterfaces.dll
位置在
Photon-OnPremise-Server-SDK_v4-0-29-11263\lib
新增後它會直接copy,生成解決方案時直接在裡面了,不用擔心後期的移植。
6.新增服務端入口
6.1-繼承自抽象類:
ApplicationBase
並實現所有抽象介面
7.生成新類,用於和客戶端通訊,且該類繼承自:
ClientPeer
7-1:實現抽象類,實現建構函式並繼承自父類
8.建立連結:
當有使用者請求連結時,會發送資料包給伺服器,也就是main,這個時候,你需要生成一個Client去和他通訊
返回你的伺服器入口
8.5:生成解決方案
8.5-1:建立資料夾,放置你的解決方案
8.5-2:在改這個資料夾裡面建立bin資料夾
8.5-3:進入專案,選中,右鍵->屬性,生成,下面的生成選項的路徑到bin,生成解決方案,不會的回去學習vs怎麼用
9.給你的伺服器新增配置
9-1:點開後開啟
找到這個 標籤
它描述的就是一個伺服器的所有配置,複製這個標籤裡面的所有內容
這個標籤外再貼上
首先是標籤名:
改成你喜歡的名字,前後要對稱
9-2往下找,找到這個標籤
Default = 你的伺服器名字=SavageCollision
Name = 你的伺服器名字=SavageCollision
BaseDirectory = 你生成的類庫的資料夾=SavageCollision
Assembly = 專案名字=SavageCollission
Type =名稱空間.伺服器入口類名
9-3:至於有些顯示名字最好改一下,你可以參考下下面的配置
<SavageCollision
MaxMessageSize="512000"
MaxQueuedDataPerPeer="512000"
PerPeerMaxReliableDataInTransit="51200"
PerPeerTransmitRateLimitKBSec="256"
PerPeerTransmitRatePeriodMilliseconds="200"
MinimumTimeout="5000"
MaximumTimeout="30000"
DisplayName="SavageCollision"
>
<!-- 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="SavageCollision">
</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="SavageCollision"
>
</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="SavageCollision">
</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="SavageCollision">
<Application
Name="SavageCollision"
BaseDirectory="SavageCollision"
Assembly="SavageCollision"
Type="SavageCollision.Main"
ForceAutoRestart="true"
WatchFiles="dll;config"
ExcludeFiles="log4net.config">
</Application>
</Applications>
</SavageCollision>
執行Photon.exe
右鍵右下角的photon圖示,開啟日誌,觀察
執行成功!