Unity服务器开发03:部署PhotonServer服务器

编程入门 行业动态 更新时间:2024-10-28 04:16:09

Unity<a href=https://www.elefans.com/category/jswz/34/1771423.html style=服务器开发03:部署PhotonServer服务器"/>

Unity服务器开发03:部署PhotonServer服务器

Unity服务器开发03:部署PhotonServer服务器

前篇文章:
Unity服务器开发02:搭建NHibernate框架

(一)创建第一个服务器端项目

1.创建解决方案,命名MyGameServer,添加PhotonServer的引用

(二)开发ApplicationBase和ClientPeer
1.创建类库,命名MyGameServer,并创建两个类MyGameServer和ClientPeer

2.MyGameServer类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Photon.SocketServer;namespace MyGameServer
{//所有的server端主类都要集成自applicationbasepublic class MyGameServer : ApplicationBase{//当一个客户端请求链接的//我们使用peerbase,表示和一个客户端的链接protected override PeerBase CreatePeer(InitRequest initRequest){return new ClientPeer(initRequest);}//初始化,最先调用protected override void Setup(){}//server端关闭的时候protected override void TearDown(){}}
}

3.ClientPeer类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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){}//处理客户端请求protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters){}}
}

4.生成解决方案,将生成文件存储于PhotonServer文件夹中,参考路径:D:\Photon-OnPremise-Server-SDK_v4-0-29-11263\deploy\MyGameServer\bin

(三)部署并启动第一个服务器端应用
1.在PhotonServer文件夹中用VS打开PhotonServer.config,参考路径:D:\Photon-OnPremise-Server-SDK_v4-0-29-11263\deploy\bin_Win64

2.在配置文件中的Configuration标签里加入项目配置信息

<!-- Instance settings --><MyGameInstanceMaxMessageSize="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><UDPListenerIPAddress="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><TCPListenerIPAddress="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. --><RuntimeAssembly="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 --><ApplicationName="MyGame1"BaseDirectory="MyGameServer"Assembly="MyGameServer"Type="MyGameServer.MyGameServer"ForceAutoRestart="true"WatchFiles="dll;config"ExcludeFiles="log4net.config"></Application></Applications></MyGameInstance>

3.打开PhotonControl.exe,启动My Game项目,打开日志检查PhotonServer是否运行

Service is running,服务器应用部署成功。

更多推荐

Unity服务器开发03:部署PhotonServer服务器

本文发布于:2023-07-28 15:48:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1240057.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:服务器   Unity   PhotonServer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!