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

本文详细介绍了如何下载和安装PhotonServer,包括在VS2019中创建C#类库项目,添加引用,重写方法,生成项目。接着,配置PhotonServer.config文件,设置监听端口和应用程序信息,最后启动服务器。
摘要由CSDN通过智能技术生成
  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项目了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值