unity服务器Photon Server学习笔记

发布时间:2024-11-19 点击:55
(一)服务端
新建类库
引用:exitgameslibs,photon.socketserver,photonhostruntimeinterfaces
applicationbase
using chatserver.properties; using photon.socketserver; using system; using system.collections.generic; using system.linq; using system.text; namespace chatserver { /// <summary> /// 继承applicationbase的类是入口程序,也是启动程序 /// </summary> public class chartserver : applicationbase { /// <summary> /// 客户端连接到这个server端调用 /// </summary> /// <param name="initrequest"></param> /// <returns></returns> protected override peerbase createpeer(initrequest initrequest) { return new chartpeerbase(initrequest.protocol, initrequest.photonpeer); } /// <summary> /// server端启动时调用 /// </summary> protected override void setup() { } /// <summary> /// 这个server端停掉时调用 /// </summary> protected override void teardown() { } } }
peerbase
using photon.socketserver; using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using photonhostruntimeinterfaces; namespace chatserver.properties { /// <summary> /// 用来和客户端进行通信 /// </summary> class chartpeerbase : peerbase { public chartpeerbase(irpcprotocol protocol, iphotonpeer unmanagedpeer):base(protocol,unmanagedpeer) { } protected override void ondisconnect(disconnectreason reasoncode, string reasondetail) { throw new notimplementedexception(); } protected override void onoperationrequest(operationrequest operationrequest, sendparameters sendparameters) { throw new notimplementedexception(); } } }
设置输出
在下载好的sdk目录下新建文件mychartserver,并在文件下新建bin目录
项目-chatserver属性(alt f7)-生成-输出路径为exitgames-photon-server-sdk_v3-4-31-10808deploymychartserverbin
配置文件
exitgames-photon-server-sdk_v3-4-31-10808deploybin_win64配置photonserver.config文件下
application name=”lite”和”litelobby”间加入新的application,配置如下
<applications default="lite"> <!– lite application –> <application name="lite" basedirectory="lite" assembly="lite" type="lite.liteapplication" forceautorestart="true" watchfiles="dll;config" excludefiles="log4net.config"> </application> <!– chartserver application –> <application name="chartserver"//自定义name basedirectory="mychartserver"//文件目录,如我的文件在deploy下mychartserver文件夹下 assembly="chatserver"//继承applicationbase的类所在命名空间 type="chatserver.chartserver"//继承applicationbase的类所在命名空间 类名 forceautorestart="true" watchfiles="dll;config" excludefiles="log4net.config"> </application> <!– litelobby application –> <application name="litelobby" basedirectory="litelobby" assembly="litelobby" type="litelobby.litelobbyapplication" forceautorestart="true" watchfiles="dll;config" excludefiles="log4net.config"> </application>
(二)客户端
新建控制台程序
引用 photon3dotnet
using exitgames.client.photon; using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespac

关于Golang GC 垃圾回收机制的详解
2019年最全的域名投资及技巧
如何租用云服务器做渲染
谈谈企业上云的四大重点与五大阶段
主机不能访问-虚拟主机/数据库问题
阿里云服务器没有备案域名能用吗
行业动态与宠物网站建设
独立站岂止于外贸,国内官方私域引流之七脉神剑