Photon Server的服务器端配置
Photon Server与Unity3D的交互分为3篇博文实现
(3)Photon Server与Unity3D客户端的交互
Photon Server是一款实时的Socket服务器和开发框架,快速、使用方便、容易扩展,服务端架构在Windows系统平台上,采用C#语言编写,Photon Server发布包括两个部分,Client SDK Release和Server SDK Update,Server SDK的版本是v2.4.5,而Client SDK的版本是v6.2.0。客户端SDK提供了多种平台的开发API,包括DotNet,Unity3D,C/C++等。SDK就是指可以为第三方开发者提供特定的软件包、软件框架、硬件平台、操作系统等创建应用软件开发工具的集合,并且SDK还能简单的为某个程序设计语言提供应用程序接口API的一些文件。
PhotonServer官网:https://www.photonengine.com/en/OnPremise。帮助文档:官网Documentatain右边的Tutorials、Reference和\Photon-OnPremise-Server-SDK_v4-0-29-11263\doc
1.下载Server SDK(On-Premises)
进入官网,点击页面右上角的SDKs,然后在Choose for your project的条件中选中Server,可以看到图标
,点击图标后点Download SDK下载exe文件。运行或右键解压服务器端,不要出现中文目录,解压出\ Photon-OnPremise-Server-SDK_v4-0-29-11263。

\deploy:部署服务器应用,放置开发服务器的代码及相关文件(\deploy\bin_Win64\PhotonControl.exe:服务器程序运行文件,证书存放的在\deploy\bin_Win64)
\doc:存放帮助文档
\lib:存放动态链接库(Photon3Unity3D.dll是用来开发基于Unity3D的客户端,ExitGamesLibs.dll、Photon.SocketServer.dll、PhotonHostRuntimeInterfaces.dll是用来开发服务器端)
\src-server:提供一些项目的源码
2. 配置server端的PhotonServer.config文件
打开deploy\bin_Win64\PhotonServer.config。一个Photon instance代表一类配置,一个Photon instance可以包含多个服务器端的应用。
<MMoInstance <!--这个Photon instances的名称-->
MaxMessageSize=""
MaxQueuedDataPerPeer=""
PerPeerMaxReliableDataInTransit=""
PerPeerTransmitRateLimitKBSec=""
PerPeerTransmitRatePeriodMilliseconds=""
MinimumTimeout=""
MaximumTimeout=""
DisplayName="MMO" <!--显示在Photon instances的名称-->
> <!-- 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=""
OverrideApplication="Minecraft">"<!--指明这个端口号是给哪个Application使用的-->
</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=""
PolicyFile="Policy\assets\socket-policy.xml"
InactivityTimeout=""
OverrideApplication="Minecraft"
>
</TCPListener>
</TCPListeners> <!-- Policy request listener for Unity and Flash (port 843) and Silverlight (port 943) -->
<PolicyFileListeners>
<!-- multiple Listeners allowed for different ports -->
<PolicyFileListener
IPAddress="0.0.0.0"
Port=""
PolicyFile="Policy\assets\socket-policy.xml"
InactivityTimeout="">
</PolicyFileListener>
<PolicyFileListener
IPAddress="0.0.0.0"
Port=""
PolicyFile="Policy\assets\socket-policy-silverlight.xml"
InactivityTimeout="">
</PolicyFileListener>
</PolicyFileListeners> <!-- WebSocket (and Flash-Fallback) compatible listener -->
<WebSocketListeners>
<WebSocketListener
IPAddress="0.0.0.0"
Port=""
DisableNagle="true"
InactivityTimeout=""
OverrideApplication="Minecraft">
</WebSocketListener>
</WebSocketListeners> <!-- 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="Minecraft"><!--客户端连接服务器未指定Application时连接默认的Application-->
<!-- MMO Demo Application -->
<Application
Name="Minecraft"<!--应用名称-->
BaseDirectory="MinecraftServer"<!--\deploy下这个服务器应用的文件名称-->
Assembly="MinecraftServer"<!-—程序集名称-->
Type="MinecraftServer.MinecraftServer"<!--主类名称-->
ForceAutoRestart="true"<!--是否自动重启-->
WatchFiles="dll;config"
ExcludeFiles="log4net.config">
</Application> <!-- CounterPublisher Application -->
<Application
Name="CounterPublisher"
BaseDirectory="CounterPublisher"
Assembly="CounterPublisher"
Type="Photon.CounterPublisher.Application"
ForceAutoRestart="true"
WatchFiles="dll;config"
ExcludeFiles="log4net.config">
</Application> </Applications>
</MMoInstance>
3.创建server端类库
(1)创建类库:文件-新建-项目-类库,创建类库MinecraftServer
(2)创建Application文件夹:在\deploy下创建文件夹MinecraftServer(与配置文件PhotonServer.config里Application中的BaseDirectory对应),然后在Minecraft下创建文件夹bin
(3)设置dll文件生成路径:右键项目-属性-生成-输出路径,设置为\deploy\MinecraftServer\bin
(4)修改程序集名称跟默认命名空间:右键项目-属性-应用程序,都设置为MinecraftServer(与配置文件PhotonServer.config里Application中的Assembly对应)。
(5)生成dll文件:右键项目-生成。以后每次修改都要重新生成。
4.添加server端动态链接库
在\lib里,将ExitGamesLibs.dll、Photon.SocketServer.dll、PhotonHostRuntimeInterfaces.dll 添加到类库引用
5.创建Server端主类与客户端连接类
主类命名用项目名称MinecraftServer并继承ApplicationBase,该类为服务器端程序入口。
using Photon.SocketServer;
namespace MinecraftServer
{
//所有的server端主类都要继承自Application
public class MinecraftServer: ApplicationBase
{
//server端启动的时候调用,作初始化
protected override void Setup()
{ }
//当一个客户端请求连接时调用,我们使用一个PeerBase表示Server端和一个客户端的连接,用来管理server端与客户端请求的发送与接收
protected override PeerBase CreatePeer(InitRequest initRequest)
{
return new ClientPeer(initRequest);//ClientPeer继承自PeerBase,InitRequest包含连接请求的各种参数。new出来后PhotonServer会帮我们管理ClientPeer。
}
//server端关闭的时候调用
protected override void TearDown()
{
}
}
}
客户端连接类ClientPeer继承PeerBase,每一个客户端连接进来都会创建一个ClientPeer,用来管理server端与客户端请求的发送与接收
using Photon.SocketServer;
using PhotonHostRuntimeInterfaces;
namespace MinecraftServer
{
//每一个客户端连接进来都会创建一个ClientPeer
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)
{ }
}
}
6.配置日志
(1)添加动态链接库log4net.dll(log4net是做日志输出的插件)和ExitGames.Logging.Log4Net.dll(Photon提供用来连接Photon与log4net)。右键引用-添加引用-浏览,在\lib里。
(2)配置log4net.config。参考\src-server\Mmo\Photon.MmoDemo.Server\log4net.config。详细学习推荐上官网http://logging.apache.org/log4net或博客园。
<?xml version="1.0" encoding="utf-8" ?>
<log4net debug="false" update="Overwrite"> <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="%property{Photon:ApplicationLogPath}\\Minecraft.Server.log" /><!--value表示日志文件所在的完整路径,property{Photon:ApplicationLogPath}是根目录在MyGameServer.cs里配置,Minecraft.Server.log日志的名称 -->
<appendToFile value="true" />
<maximumFileSize value="5000KB" />
<maxSizeRollBackups value="" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender> <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="DEBUG" />
<levelMax value="FATAL" />
</filter>
</appender> <!-- logger -->
<root>
<level value="INFO" />
<!--<appender-ref ref="ConsoleAppender" />-->
<appender-ref ref="RollingFileAppender" />
</root> <logger name="OperationData">
<level value="INFO" />
</logger> </log4net>
<!--这个文档的复制到输出目录要选择始终复制 -->
(3)日志初始化
using Photon.SocketServer;
using ExitGames.Logging;
using ExitGames.Logging.Log4Net;
using System.IO;
using log4net.Config;
namespace MinecraftServer
{ //所有的server端主类都要继承自Application
public class MinecraftServer: ApplicationBase
{
//需using ExitGames.Logging;log用来做日志输出
public static readonly ILogger log = LogManager.GetCurrentClassLogger();
//server端启动的时候调用,作初始化
protected override void Setup()
{
//日志的初始化
//this.ApplicationRootPath获取photonServer应用的根目录(D:\Photon-OnPremise-Server-SDK_v4-0-29-11263\deploy)
log4net.GlobalContext.Properties["Photon:ApplicationLogPath"] = Path.Combine(Path.Combine(this.ApplicationRootPath, "bin_Win64"), "log");
//Path.Combine() 会屏蔽平台的差异。this.BinaryPath获取输出路径(D:\Photon-OnPremise-Server-SDK_v4-0-29-11263\deploy\MyGameServer\bin)
FileInfo configFileInfo = new FileInfo(Path.Combine(this.BinaryPath, "log4net.config"));//需using System.IO;
if(configFileInfo.Exists)
{
LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);//让photon知道使用的是Log4Net的日志插件。需using ExitGames.Logging.Log4Net;
XmlConfigurator.ConfigureAndWatch(configFileInfo);//让log4net这个插件读取配置文件。需using log4net.Config;
} //日志输出
log.Info("服务器应用启动成功!");
} //当一个客户端请求连接时调用,我们使用一个PeerBase表示Server端和一个客户端的连接,用来管理server端与客户端请求的发送与接收
protected override PeerBase CreatePeer(InitRequest initRequest)
{
log.Info("一个客户端应用连接进来!");
return new ClientPeer(initRequest);//ClientPeer继承自PeerBase,InitRequest包含连接请求的各种参数
}
//server端关闭的时候调用
protected override void TearDown()
{
log.Info("服务器应用关闭!");
}
}
}
MinecraftServer.log.Info输出Info类信息,MinecraftServer.log.Debug输出Debug类信息,MinecraftServer.log.Error输出Error类信息等为日志的输出做分类。

一个应用有3个日志文件:Photon.CLR(输出应用的配置信息跟Listeners的信息)、Photon-MMoInstance-20180212.log(MMoInstance模块应用启动顺序的输出)、Minecraft.Server.log(自定义的输出)。
Photon Server的服务器端配置的更多相关文章
- Photon Server的Unity3D客户端配置
Photon Server与Unity3D的交互分为3篇博文实现 (1)Photon Server的服务器端配置 (2)Photon Server的Unity3D客户端配置 (3)Photon Ser ...
- Photon Server与Unity3D客户端的交互
Photon Server与Unity3D的交互分为3篇博文实现 (1)Photon Server的服务器端配置 (2)Photon Server的Unity3D客户端配置 (3)Photon Ser ...
- 看过自会理解, Photon Server 常见概念分析.
http://stackoverflow.com/questions/10823915/photon-server-newbie-questions/11653419#11653419 Channel ...
- CAS客户端服务器端配置步骤
来自我的个人网站:http://lkf.22web.org/ cas介绍: CAS 是 Yale 大学发起的一个开源项目,旨在为 Web 应用系统提供一种可靠的单点登录方法,CAS 在 2004 年 ...
- Unity3d Web Player 与server端联网配置
针对Unity3d Web Player 的server端联网配置写一随笔咯. 以SmartFoxServer2X官方的Unity3d Example ”tris“为例,部署好服务器之后,在Unit ...
- CAS单点登录配置[3]:服务器端配置
在准备工作,证书生成等工作完成后,本篇介绍服务器端的配置. JDK配置 1 我们将生成的cacerts文件分别拷贝到JDK目录下的jre/lib/security目录下及JRE对应的目录中,如果之前存 ...
- Unity3d Web Player 的server端联网配置
新游戏出了第一个能跑完流程的版本,不得不佩服Unity3D强大的功力,PC.MAC OS.Linux.IOS.Android.web player,前天刚发布的unity3d 4.2版本还支持WIND ...
- CentOS6.5下VNC Server远程桌面配置详解
参考文献: (总结)CentOS Linux下VNC Server远程桌面配置详解 远程桌面连接工具VNC——license Key 我的下载地址为 太平洋下载 VNC连接黑屏的问题 centos 6 ...
- NFS服务器端配置
服务器端配置1 创建共享目录# mkdir /home/share# chown nobody.nogroup /home/share2 创建或修改/etc/exports 配置文件这个文件的内容非常 ...
随机推荐
- applicationContext-redis.xml配置文件
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...
- Array排序和List排序
public class SortTest { public static void main(String[] args) { int arr[]={12,4,45,23,5,7,9,33}; Sy ...
- Shiro学习(20)无状态Web应用集成
在一些环境中,可能需要把Web应用做成无状态的,即服务器端无状态,就是说服务器端不会存储像会话这种东西,而是每次请求时带上相应的用户名进行登录.如一些REST风格的API,如果不使用OAuth2协议, ...
- JCF——工具类
- Shell基础(一):Shell基础应用、简单Shell脚本的设计、使用Shell变量、变量的扩展应用
一.Shell基础应用 目标: 本案例要求熟悉Linux Shell环境的特点,主要练习以下操作: 1> 切换用户的Shell环境 2> 练习命令历史.命令别名 3 ...
- linq中如何合并多个predicate条件
最近在做一个webAPI 的时候遇到一个需要合并多个predicate条件的问题,下面就是对题的情况.为了方便交流我对case进行了简化,请先看如下代码: using System.Collectio ...
- xshell突出显示集
xshell突出显示集(参考mobaxterm,直接拷贝过来不行,应该是xshell对正则表达式的支持不够好): Underline: \b(http(s)?://[A-Za-z0-9_./& ...
- JAVA调用R脚本 windwos路径下
RConnection c = new RConnection();// REXP x = c.eval("source('D:\\\\jiaoben\\\\RJava_test.R',en ...
- C#之winform 猜拳小游戏
C#之winform 猜拳小游戏 1.建立项目文件 2.进行界面布局 2.1 玩家显示(控件:label) 2.2 显示玩家进行选择的控件(控件:label) 2.3 电脑显示(控件:label) ...
- 21、Linux命令对服务器网络进行监控
带宽在我们性能测试中是非常重要的一个因素,带宽的理论上传/下载速度是可以进行推算的.比如你的带宽是10m,那么上传/下载理论速度是10/8=1.25m/s.举个例子,服务器上一个文件大小1.25M,我 ...