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图标,打开日志,观察
运行成功!