Unity PhotonServer服务器开发(一)

PhotonServer 

下载:https://www.photonengine.com/en-US/sdks#realtime

解压

打开deploy

根据电脑打开bin_Win32/bin_Win64

启动PhotonControl

创建服务器

在deploy文件夹中创建新文件夹

在新建的文件夹中创建新文件夹并取名为bin

打开VS,新建项目

可以删除class1

添加引用(浏览,找到上面解压的lib文件夹)

  • ExitGames.Logging.Log4Net.dll
  • log4net.dll
  • Photon.SocketServer.dll
  • ExitGamesLibs.dll
  • PhotonHostRuntimeInterfaces.dll

创建类并公开

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestSever
{
    public class TestSeverClass
    {
    }
}

将此类设为入口

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

namespace TestSever
{
    public class TestSeverClass : ApplicationBase
    {
        //有客户端连接时调用
        protected override PeerBase CreatePeer(InitRequest initRequest)
        {
            PeerClass peer = new PeerClass(initRequest);
            return peer;
        }

        //初始化时
        protected override void Setup()
        {

        }

        //关闭服务器时
        protected override void TearDown()
        {

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

namespace TestSever
{
    public class PeerClass : ClientPeer
    {
        public PeerClass(InitRequest initRequest):base(initRequest)
        {

        }
        protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)
        {

        }

        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {

        }
    }
}

修改输出路径

右击命名空间,选择属性,选择生成,修改输出路径,修改为前面自己创建的bin文件夹。

再次右击命名空间,选择生成

找到bin_Win64/bin_Win32中配置文件photonServer.config并打开(拖到VS即可)

在打开的XML文件中的<Configuration></Configuration>间写入下面节点(根据实际情况自行修改)并保存。

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

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

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

    </Applications>
  </TestSever>

重新启动打开PhotonControl 

即可看到自己添加的服务器。

选择此服务器后选择start as application即可启动。

选择stop application即停止。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值