unity学习笔记(五)——配置Photon Server

  1. 下载Photon Server

下载地址:https://www.photonengine.com/zh-cn/sdks#sdkserverserver

选择下载Photon Server SDK

安装

安装后文件如图所示

  1. 创建Photon Server新项目

创建新项目的文件夹

在deploy下面创建【项目名】/【bin】

该文件夹用于存放项目生成的文件

  1. 创建项目

打开VS2019,创建项目。

项目为【C#】类型的【类库(.NET Framework)】

  1. 开发项目

  1. 添加引用,添加下图的五个引用,改引用在【photon-server-sdk_v5-0-12-24499-rc1\lib】中。

  1. 修改类名和初始文件名为【PSTest】

  1. 【PSTest】继承【ApplicationBase】,并生成以下3个重载方法(按ALT+ENTER快速生成)

  1. 重写CreatePeer方法,CreatePeer需要返回一个PeerBase类,所以我们创建一个新的类【PSPeer】,【PSPeer】继承于【ClientPeer】。并生成以下2个重载方法,和构造函数。

  1. 生成项目

修改类库生成构建依赖的地址为刚刚创建的新项目的地址、点击【生成】即可生成项目。

  1. 配置项目

打开PhotonServer.config文件

在Configuration标签下加上下面的代码

<PSTest
    MaxMessageSize="512000"
    MaxQueuedDataPerPeer="512000"
    PerPeerMaxReliableDataInTransit="51200"
    PerPeerTransmitRateLimitKBSec="256"
    PerPeerTransmitRatePeriodMilliseconds="200"
    MinimumTimeout="5000"
    MaximumTimeout="30000"
    DisplayName="PSTest"
        >

        <!-- 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="PSTest">
            </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="PSTest"
                >
            </TCPListener>
        </TCPListeners>



        <!-- 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="PSTest">

            <!-- MMO Demo Application -->
            <Application
                Name="PSTest"
                BaseDirectory="PSTest"
                Assembly="PSTest"
                Type="PSTest.PSTest"
                ForceAutoRestart="true"
                WatchFiles="dll;config"
                ExcludeFiles="log4net.config">
            </Application>

        </Applications>
    </PSTest>

注:Type="PSTest.PSTest"是因为PSTest类在命名空间的PSTest下,这样写才能找到他。

这样就可以启动Photon Server项目了

猜你喜欢

转载自blog.csdn.net/ximi2231/article/details/129557799
今日推荐