002_Photon服务端框架

---------------------------------------李明阳---2016/5/29---------ExitGames-Photon-Server-SDK_v3-4-31-10808------------------------

创建C#项目类库

Application主类

Application.cs

Application类继承ApplicationBase

public class MyApplication : ApplicationBase

实现ApplicationBase接口

Application增加日志输出功能

//日志输出(调用log.Debug("");)

private static readonly ILogger log = ExitGames.Logging.LogManager.GetCurrentClassLogger();

#region ApplicationBase

//创建和客户端通信的Peer类

protected override PeerBase CreatePeer(InitRequest initRequest)

{

return new ClientPeer(initRequest.Protocol, initRequest.PhotonPeer);

}

//为Photon增加日志输出用来查看服务端的运行状况

protected override void Setup()

{

ExitGames.Logging.LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);

GlobalContext.Properties["Photon:ApplicationLogPath"] = Path.Combine(this.ApplicationRootPath, "log");

GlobalContext.Properties["LogFileName"] = "My" + this.ApplicationName;

XmlConfigurator.ConfigureAndWatch(new FileInfo(Path.Combine(this.BinaryPath, "log4net.config")));

log.Debug("Application setup complete.");

}

//当PhotonSerer停止时调用

protected override void TearDown()

{

log.Debug("Application tear down.");

}

#endregion

处理客户端请求类

ClientPeer.cs

继承自PeerBase

public class ClientPeer : PeerBase

Peer构造函数

public ClientPeer(IRpcProtocol protocol, IPhotonPeer peer)

: base(protocol, peer)

{

}

ClientPeer增加日志输出功能

//日志输出(调用log.Debug("");)

private static readonly ILogger log = ExitGames.Logging.LogManager.GetCurrentClassLogger();

实现PeerBase接口

#region PeerBase

protected override void OnDisconnect(PhotonHostRuntimeInterfaces.DisconnectReason reasonCode, string reasonDetail)

{

}

//处理客户端传递来的消息,同时客户端返回消息(SendOperationResponse(response, sendParameters);)

protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)

{

OperationResponse response = new OperationResponse();

response.OperationCode = operationRequest.OperationCode;

response.Parameters = new Dictionary<byte, object>();

SendOperationResponse(response, sendParameters);

log.Debug("operation code : " + operationRequest.OperationCode);

}

#endregion

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------//

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------//

//-------------------------------以上内容完成Unity3D客户端和PhotonServer的通信框架-----------------------------------------------------//

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------//

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------//

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值