Photon_部署PhotonServer 服务端项目_011


第一步创建项目

首先创建一个VS项目,不同的是这次创建的项目是类库
这里写图片描述


第二步创建部署的目录

在deploy目录下面创建MyGameServer目录,并在MyGameServer下创建bin目录
这里写图片描述


第三步修改项目的生成目录

因为此项目是一个类库项目,所以会生成一些文件
我们将这些文件直接放入第二步创建的目录中
这里写图片描述
这里写图片描述
这里写图片描述
这样在我们完成项目的时候选择项目,右键,点击生成就可以在此目录下面看到生成的文件了


第四步 添加必要的引用

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述


第五步创建主类

创建MyGameServer类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Photon.SocketServer;
using ExitGames.Logging;
using ExitGames.Logging.Log4Net;
using System.IO;
using log4net.Config;

namespace MyGameServer
{
    //所有的server端 主类都要继承自ApplicationBase类
    //ApplicationBase 是一个抽象类 我们需要实现他的所有的抽象方法
    public class MyGameServer : ApplicationBase
    {
        //当一个客户端请求连接的时候
        //我们使用peerbase 表示和一个客户端的连接
        protected override PeerBase CreatePeer(InitRequest initRequest)
        {
            return new ClientPeer(initRequest);
        }
        //初始化
        protected override void Setup()
        {
        }
        //Server端关闭的时候
        protected override void TearDown()
        {

        }
    }
}

第六步 创建一个用户连接类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Photon;
using Photon.SocketServer;
using PhotonHostRuntimeInterfaces;

namespace MyGameServer
{
    public class ClientPeer : Photon.SocketServer.ClientPeer
    {
        public ClientPeer(InitRequest initRequest) : base(initRequest)
        {
        }
        //断开连接
        protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)
        {
            throw new NotImplementedException();
        }
        //发送请求
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            throw new NotImplementedException();
        }
    }
}

第七步配置文件

该配置文件位于\deploy\bin_Win64文件夹下
这里写图片描述
此文件是一个文本文件,为了便于我们编辑我们可以使用VS打开
在此文件中Configurtion标签中包含两个系统自带的项目
LoadBalancing和MMoDemo
类似下面的图
这里写图片描述

我们可以复制其中一个开始更改我们现在要部署的项目

    <!-- Instance settings -->
  <!-- DisplayName 就是项目启动时启动的名字 -->
    <MyGameInstance
        MaxMessageSize="512000"
        MaxQueuedDataPerPeer="512000"
        PerPeerMaxReliableDataInTransit="51200"
        PerPeerTransmitRateLimitKBSec="256"
        PerPeerTransmitRatePeriodMilliseconds="200"
        MinimumTimeout="5000"
        MaximumTimeout="30000"
        DisplayName="My Game"
        >

        <!-- 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="MyGame1">
            </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="MyGame1"               
                >
            </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="MyGame1">

            <!-- MMO Demo Application -->
      <!--BaseDirectory="MyGameServer" 我们在deploy下创建的目录-->
      <!--Assembly="MyGameServer" 程序集-->
      <!--Type="MyGameServer.MyGameServer" 就是主类的路径 含义:在MyGameServer命名空间下的MyGameServer类-->
            <Application
                Name="MyGame1"
                BaseDirectory="MyGameServer"
                Assembly="MyGameServer"
                Type="MyGameServer.MyGameServer"
                ForceAutoRestart="true"
                WatchFiles="dll;config"
                ExcludeFiles="log4net.config">
            </Application>
        </Applications>
    </MyGameInstance>

这样我们就可以启动自己的项目了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yy763496668

您的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值