1.下载环境
环境下载地址

2.解压文件

3.下载Licenses

Licenses下载地址

4.将下载好的Licenses文件复制到deploy\bin_Win64目录

5.成功后如图所示

6.创建C#类库项目

  1. .NET4.5版本,起名MyGameServer
  2. 引入DLL(lib目录下): ExitGamesLibs.dll、Photon.SocketServer.dll、PhotonHostRuntimeInterfaces.dll
  3. 代码
    public class MyGameServer : ApplicationBase{//当一个客户端请求连接的时候protected override PeerBase CreatePeer(InitRequest initRequest){return new ClientPeer(initRequest);}//初始化protected override void Setup(){}//server端关闭的时候protected override void TearDown(){}}
    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){}}

7.将编译好的dll复制到deploy\MyGameServer\bin,文件夹需要手动创建
8.修改deploy\bin_Win64\PhotonServer.config配置文件

 <MyGameInstanceMaxMessageSize="512000"MaxQueuedDataPerPeer="512000"PerPeerMaxReliableDataInTransit="51200"PerPeerTransmitRateLimitKBSec="256"PerPeerTransmitRatePeriodMilliseconds="200"MinimumTimeout="5000"MaximumTimeout="30000"DisplayName="My Game"><UDPListeners><UDPListenerIPAddress="0.0.0.0"Port="5055"OverrideApplication="MyGame1"></UDPListener></UDPListeners><TCPListeners><TCPListenerIPAddress="0.0.0.0"Port="4530"PolicyFile="Policy\assets\socket-policy.xml"InactivityTimeout="10000"OverrideApplication="MyGame1"></TCPListener></TCPListeners><RuntimeAssembly="PhotonHostRuntime, Culture=neutral"Type="PhotonHostRuntime.PhotonDomainManager"UnhandledExceptionPolicy="Ignore"></Runtime><!--BaseDirectory:编译好的dll所在文件夹名--><!--Assembly:dll名--><!--Type:命名空间.类名--><Applications Default="MyGame1"><ApplicationName="MyGame1"BaseDirectory="MyGameServer"Assembly="MyGameServer"Type="MyGameServer.MyGameServer"ForceAutoRestart="true"WatchFiles="dll;config"ExcludeFiles="log4net.config"></Application></Applications></MyGameInstance>

9.添加日志文件
1.引入类库lib\log4net.dll、ExitGames.Logging.Log4Net.dll
2.添加配置文件,复制src-server\Mmo\Photon.MmoDemo.Server\log4net.config到项目中
3.修改配置文件

<file type="log4net.Util.PatternString" value="%property{Photon:ApplicationLogPath}\\MyGame.Server.log" />

4.修改log4net.config文件属性为始终复制
5.添加配置日志的代码

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExitGames.Logging;
using ExitGames.Logging.Log4Net;
using log4net.Config;
using Photon.SocketServer;namespace MyGameServer
{public class MyGameServer : ApplicationBase{private static readonly ILogger log = LogManager.GetCurrentClassLogger();//当一个客户端请求连接的时候protected override PeerBase CreatePeer(InitRequest initRequest){return new ClientPeer(initRequest);}//初始化protected override void Setup(){InitLog();log.Info("初始化成功");}//server端关闭的时候protected override void TearDown(){}#region 日志/// <summary>/// 初始化日志以及配置/// </summary>private void InitLog(){//日志的初始化log4net.GlobalContext.Properties["Photon:ApplicationLogPath"] = this.ApplicationRootPath + @"\bin_Win64\log";//设置日志的路径FileInfo configFileInfo = new FileInfo(this.BinaryPath + @"\log4net.config");//获取配置文件if (configFileInfo.Exists){LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);XmlConfigurator.ConfigureAndWatch(configFileInfo);}}#endregion}
}

6.添加日志的文件到日志控制台上

7.服务器和unity端交互,基本代码
服务器端

using Photon.SocketServer;
using PhotonHostRuntimeInterfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;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){switch (operationRequest.OperationCode){case 1://收到Dictionary<byte, object> data = operationRequest.Parameters;MyGameServer.log.Info("收到客户端消息:" + data[1].ToString());//返回OperationResponse operationResponse = new OperationResponse();operationResponse.OperationCode = 1;Dictionary<byte, object> data2 = new Dictionary<byte, object>();data2.Add(1, "你好,我是服务器");operationResponse.Parameters = data2;SendOperationResponse(operationResponse, sendParameters);break;default:break;}}}
}

unity端

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ExitGames.Client.Photon;public class PhotonEngine : MonoBehaviour, IPhotonPeerListener
{private PhotonPeer peer;void Start(){peer = new PhotonPeer(this, ConnectionProtocol.Udp);peer.Connect("127.0.0.1:5055", "MyGame");}void Update(){peer.Service();}public void DebugReturn(DebugLevel level, string message){}/// <summary>/// 接收服务器事件/// </summary>/// <param name="eventData"></param>public void OnEvent(EventData eventData){}/// <summary>/// 接收服务器响应/// </summary>/// <param name="operationResponse"></param>public void OnOperationResponse(OperationResponse operationResponse){}/// <summary>/// 状态改变/// </summary>/// <param name="statusCode"></param>public void OnStatusChanged(StatusCode statusCode){Debug.Log(statusCode);}/// <summary>/// 向服务器发送响应/// </summary>public void SendOperation(){peer.OpCustom(1, new Dictionary<byte, object>(), true);}
}

Photon Server搭建(一)相关推荐

  1. photon server服务器搭建

    闲话不多说,直接进入正题 到photonserver官网下载photon server免费版,安装后会形成一个文件夹:然后在官网下载用户使用的license,以获得服务器使用权限:将license文件 ...

  2. Lync server 2013 之office web apps server 搭建步骤

    office web apps server 搭建步骤: 一. .NET Framework 4.5 节点下的HTTP 激活 .NET Framework 3.5 Windows Identity F ...

  3. TortoiseSVN与VisualSVN Server搭建SVN版本控制系统

    本片主要介绍如何搭建SVN版本控制系统,主要使用工具: 1 客户端:TortoiseSVN (小乌龟) 2 服务端:VisualSVN Server 搭建出图形化管理,以及右键菜单版本控制管理的SVN ...

  4. Ubuntu 12.04 Server 搭建DNS服务器

    这边简单介绍一下,在Ubuntu 12.04 Server 搭建简单的DNS 服务器 #apt-get -y install bind9 bind9utils 这里我以 hasee.com 域名为例 ...

  5. windows 下使用 Filezilla server 搭建 ftp 服务器

    windows 下使用 Filezilla server 搭建 ftp 服务器 1. Filezilla server 免费,开源, ftp 服务端 2. 下载安装, windows  https:/ ...

  6. Photon Server伺服务器在LoadBalancing的基础上扩展登陆服务

    一,如何创建一个Photon Server服务 参见此博客 快速了解和使用Photon Server 二, 让LoadBalancing与自己的服务一起启动 原Photonserver.config文 ...

  7. Ubuntu Server搭建FTP服务器(2) --本地用户FTP服务器架设

    Ubuntu Server搭建FTP服务器(2) --本地用户FTP服务器架设 参考:ubuntu中文wiki百科,网址:wiki.ubuntu.org.cn 环境:Ubuntu 9.04 Serve ...

  8. TortoiseSVN与VisualSVN Server搭建SVN版本控制系统【转】

    转自:http://www.cnblogs.com/xing901022/p/4399382.html 本片主要介绍如何搭建SVN版本控制系统,主要使用工具: 1 客户端:TortoiseSVN (小 ...

  9. FileZilla Server 搭建FTP服务器

    FileZilla Server 搭建FTP服务器 1. 背景: 在免费(此类工具免费者很多)中,我的选择是FileZilla,因为它小巧.非常强大.也比较易用,且为开源软件,发展前景不错.用户也比较 ...

最新文章

  1. Python 获取图片文件大小并转换为base64编码
  2. 工作分解结构图(Work Breakdown Structure)
  3. 实现序列化与反序列化,一定要绕开这些坑!
  4. 在D-Bus适配器中声明槽
  5. 腾讯绝悟AI完全体限时开放体验,研究登上国际顶会与顶刊
  6. C#赋值运算符及解析
  7. 5大过程组与整体管理
  8. MySQL速忆笔记(更新中)
  9. 趣解 XSS和CSRF的原理
  10. trigger_name 的命名规范
  11. Django安装与开发虚拟环境搭建01
  12. TCP连接建立与释放
  13. 如何在集合中巧用Where来查找相关元素
  14. WYSISYN编辑器 Prosemirror 入门
  15. 时间linux防火墙策略,Linux防火墙简介 – iptables配置策略(示例代码)
  16. 【信息论】如何彻底理解信息和熵?
  17. 更多:Racket系统编程
  18. field方法的用法
  19. qq输入法 for linux,QQ输入法for Mac如何下载及安装
  20. win10下注册MSCOMM32控件

热门文章

  1. Java初始化VM时出错怎么办_异常 - 虚拟机初始化错误 - Error occurred during initialization of VM...
  2. Au:分析与统计面板
  3. 【字符串算法】刷题总结
  4. 一个关于未来十年的预言
  5. Modelsim安装及使用问题记录
  6. 局域网测速:iperf实现局域网点对点测试传输速度
  7. 网页游戏无法启动显示已停止工作?驱动人生8教你怎么解决乱码正常进入游戏
  8. Swagger3配置
  9. mysql 新增字段示例
  10. 微信小程序自定义左上角胶囊样式