PhotonServer项目搭建(一)

1.新建类库项目,推荐vs2019
项目命名为MyGameServer,自己随便取名
2.photonSever 文件夹下deploy文件夹下新建文件夹 MyGame,名字随便去取在这里插入图片描述
3.在MyGame文件夹下新建bin文件夹,bin名字固定在这里插入图片描述
4.项目种设置dll生成路径,直接生成到刚刚创建的din文件夹下
项目框架选4.7.2就可以了,官网推荐4.8在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
https://doc.photonengine.com/en-us/server/v4/operations/requirements
查看photon配置的页面

5.项目中添加引用在这里插入图片描述
总共5个DLL在这里插入图片描述
6.新建脚本

using Photon.SocketServer;


namespace MyGameServer
{
    public class ServerMain : ApplicationBase
    {
        protected override PeerBase CreatePeer(InitRequest initRequest)
        {
            return new Client(initRequest);
        }

        protected override void Setup()
        {
            //throw new NotImplementedException();
        }

        protected override void TearDown()
        {
           // throw new NotImplementedException();
        }
    }
}

新建Client脚本

using Photon.SocketServer;
using PhotonHostRuntimeInterfaces;


namespace MyGameServer
{
    class Client : ClientPeer
    {
        public Client(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();
        }
    }
}

重新生成dll
在这里插入图片描述
vs会把引用的dll也一并生成到生成的文件夹中
基础必须的两个类可以了,接下来配置服务器photon
下面是配置信息,保存后就直接可以在photon中运行了

<!-- Instance settings -->
	<MyGame_Instance
		MaxMessageSize="512000"
		MaxQueuedDataPerPeer="512000"
		PerPeerMaxReliableDataInTransit="51200"
		PerPeerTransmitRateLimitKBSec="256"
		PerPeerTransmitRatePeriodMilliseconds="200"
		MinimumTimeout="5000"
		MaximumTimeout="30000"
		DisplayName="My Game">		<!--DisplayName 为显示在photon上的名称 -->

	
		<UDPListeners>
			<UDPListener
				IPAddress="0.0.0.0"
				Port="8889"
				OverrideApplication="Game01"> <!--app名称-->
			</UDPListener>
		</UDPListeners>

	
		<TCPListeners>
			<TCPListener
				IPAddress="0.0.0.0"
				Port="8888"
				PolicyFile="Policy\assets\socket-policy.xml"
				InactivityTimeout="10000"
				OverrideApplication="Game01" > <!--app名称-->
				
			</TCPListener>
		</TCPListeners>
	

		<!-- Defines the Photon Runtime Assembly to use. -->
		<Runtime
			Assembly="PhotonHostRuntime, Culture=neutral"
			Type="PhotonHostRuntime.PhotonDomainManager"
			UnhandledExceptionPolicy="Ignore">
		</Runtime>

		<Applications Default="Game01">  <!--默认运行的app名称-->

			<Application>
				Name="Game01"  <!--app名称-->
				BaseDirectory="MyGame"   <!--所在deploy文件夹下的名称-->
				Assembly="MyGameServer"  <!--程序集名称-->
				Type="MyGameServer.ServerMain"  <!--命名空间和继承applicationBase的类名-->
				ForceAutoRestart="true"
				WatchFiles="dll;config"
				ExcludeFiles="log4net.config">
			</Application>

		</Applications>
	</MyGame_Instance>

7.基础日志
在这里插入图片描述
如果运行CRL没有错误日志,但是服务器启动不了,基本上是配置文件出了问题
CLR中保存的错误日志 PhotonCLR.log

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值