服务器开发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服务器
发布评论