版本:Photon-OnPremise-Server-SDK_v3-4-31-10808

输出文件夹:deploy/名称/bin

PhotonServer.config 配置

 <Applications Default="ChatServer">
<Application
Name="ChatServer"
BaseDirectory="ChatServer"
Assembly="ChatServer"
Type="ChatServer.ChatServer"
ForceAutoRestart="true"
WatchFiles="dll;config"
ExcludeFiles="log4net.config">
</Application>
</Applications>

Server端:

引用 ExitGamesLibs.dll,Photon.SocketServer.dll,PhotonHostRuntimeInterfaces.dll

 using System;
using Photon.SocketServer; namespace ChatServer {
class ChatServer:ApplicationBase { //收到客户端请求创建一个新的PeerBase
protected override PeerBase CreatePeer(InitRequest initRequest) {
return new ChatPeer(initRequest.Protocol,initRequest.PhotonPeer);
} protected override void Setup() { } protected override void TearDown() { }
}
}

ChatServer

 using System;
using System.Collections.Generic;
using Photon.SocketServer;
using PhotonHostRuntimeInterfaces; namespace ChatServer { //继承PeerBase
class ChatPeer:PeerBase { //构造函数1
public ChatPeer(InitRequest initRequest) : base(initRequest) { } //构造函数2
public ChatPeer(IRpcProtocol iRpcProtocol,IPhotonPeer iPhotonPeer) : base(iRpcProtocol,iPhotonPeer) { } protected override void OnDisconnect(DisconnectReason reasonCode,string reasonDetail) { } //收到客户端请求时执行
protected override void OnOperationRequest(OperationRequest operationRequest,SendParameters sendParameters) { Dictionary<byte,object> dict = new Dictionary<byte,object>();
dict.Add(,"void"); //创建一个新的响应操作,发送给客户端
OperationResponse response = new OperationResponse(,dict);
SendOperationResponse(response,sendParameters);
}
}
}

ChatPeer

服务端:

将Photon3Unity3D.dll放到unity Plugin文件夹中

 using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using ExitGames.Client.Photon; namespace VoidGame { public class ChatClient : MonoBehaviour,IPhotonPeerListener { private PhotonPeer peer;
private bool m_isConnected; void Start() {
peer = new PhotonPeer(this,ConnectionProtocol.Tcp);
peer.Connect("127.0.0.1:4530","ChatServer"); } void Update() {
peer.Service(); } void OnGUI() {
if(m_isConnected) {
if(GUILayout.Button("Send a operation")) {
Dictionary<byte,object> dict = new Dictionary<byte,object>();
dict.Add(,"username");
dict.Add(,"password");
peer.OpCustom(,dict,true); //发送数据到服务端
}
}
} public void DebugReturn(DebugLevel level,string message) {
Debug.Log(level + ":" + message);
} public void OnEvent(EventData eventData) {
} //收到服务端响应,获取数据
public void OnOperationResponse(OperationResponse operationResponse) {
Dictionary<byte,object> dict = operationResponse.Parameters;
object value;
dict.TryGetValue(,out value);
Debug.Log("Get value from server:" + value);
} public void OnStatusChanged(StatusCode statusCode) {
switch(statusCode) {
case StatusCode.Connect:
m_isConnected = true;
Debug.Log("Connected Success");
break;
case StatusCode.Disconnect:
break;
case StatusCode.Exception:
break;
case StatusCode.ExceptionOnConnect:
break;
case StatusCode.SecurityExceptionOnConnect:
break;
case StatusCode.QueueOutgoingReliableWarning:
break;
case StatusCode.QueueOutgoingUnreliableWarning:
break;
case StatusCode.SendError:
break;
case StatusCode.QueueOutgoingAcksWarning:
break;
case StatusCode.QueueIncomingReliableWarning:
break;
case StatusCode.QueueIncomingUnreliableWarning:
break;
case StatusCode.QueueSentWarning:
break;
case StatusCode.InternalReceiveException:
break;
case StatusCode.TimeoutDisconnect:
break;
case StatusCode.DisconnectByServer:
break;
case StatusCode.DisconnectByServerUserLimit:
break;
case StatusCode.DisconnectByServerLogic:
break;
case StatusCode.TcpRouterResponseOk:
break;
case StatusCode.TcpRouterResponseNodeIdUnknown:
break;
case StatusCode.TcpRouterResponseEndpointUnknown:
break;
case StatusCode.TcpRouterResponseNodeNotReady:
break;
case StatusCode.EncryptionEstablished:
break;
case StatusCode.EncryptionFailedToEstablish:
break;
default:
break;
}
}
}
}

ChatClient

PhotonServer 学习的更多相关文章

  1. photonServer学习之连接数据库

    string connectStr = "server=127.0.0.1;port=3306;database=database;user=root;pwd=root";//连接 ...

  2. 从直播编程到直播教育:LiveEdu.tv开启多元化的在线学习直播时代

    2015年9月,一个叫Livecoding.tv的网站在互联网上引起了编程界的注意.缘于Pingwest品玩的一位编辑在上网时无意中发现了这个网站,并写了一篇文章<一个比直播睡觉更奇怪的网站:直 ...

  3. Angular2学习笔记(1)

    Angular2学习笔记(1) 1. 写在前面 之前基于Electron写过一个Markdown编辑器.就其功能而言,主要功能已经实现,一些小的不影响使用的功能由于时间关系还没有完成:但就代码而言,之 ...

  4. ABP入门系列(1)——学习Abp框架之实操演练

    作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...

  5. 消息队列——RabbitMQ学习笔记

    消息队列--RabbitMQ学习笔记 1. 写在前面 昨天简单学习了一个消息队列项目--RabbitMQ,今天趁热打铁,将学到的东西记录下来. 学习的资料主要是官网给出的6个基本的消息发送/接收模型, ...

  6. js学习笔记:webpack基础入门(一)

    之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...

  7. Unity3d学习 制作地形

    这周学习了如何在unity中制作地形,就是在一个Terrain的对象上盖几座小山,在山底种几棵树,那就讲一下如何完成上述内容. 1.在新键得项目的游戏的Hierarchy目录中新键一个Terrain对 ...

  8. 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...

  9. 菜鸟Python学习笔记第一天:关于一些函数库的使用

    2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...

随机推荐

  1. Source Insight使用小技巧小结

    Source Insight是一款强大的代码查看工具,本身支持扩展性很好.下面我们就介绍2个扩展用例. 1.快速打开当前文件所在的目录,这个功能类似于eclipse的easyshell插件,就是能快速 ...

  2. 【实用技巧】去除BootStrap所有圆角效果

    满屏的圆角有没有审"美"疲劳啊?教你一键去除所有圆角效果: * { -webkit-border-radius: 0 !important; -moz-border-radius: ...

  3. AxeSlide软件项目梳理

    先介绍一下我负责的软件项目 AxeSlide斧子演示,估计大部分人没有听说过,但国外有一款叫Prezi的软件,应该有一部分人使用过. 这是我们产品的官网http://www.axeslide.com/ ...

  4. Java集成开发环境--Eclipse for J2EE配置JRE运行环境

    .d1 { border-style: none } .d2 { border-style: solid } .d3 { border-style: dotted } .d4 { border-sty ...

  5. 结构-行为-样式-angularJs ngAnimate(Js实现)

    声明 页面 Js 注意事项 官方链接 一.声明 注意animate的版本要与Angular的一致. <script src="jquery.1.9.1.min.js"> ...

  6. Sipdroid实现SIP(二): 呼叫请求

    INVITE 许多介绍sip的文章没有介绍以下几点细节: 重传, Timer A, B Transaction的有限状态机, 记录当前Transactin的进展情况 与INVITE消息相关的行为(Cl ...

  7. 时间序列 预测分析 R语言

    在对短期数据的预测分析中,我们经常用到时间序列中的指数平滑做数据预测,然后根据不同. 下面我们来看下具体的过程 x<-data.frame(rq=seq(as.Date('2016-11-15' ...

  8. SpringMVC @ResponseStatus 的用法

    @ResponseStatus 用于修饰一个类或者一个方法,修饰一个类的时候,一般修饰的是一个异常类,如下, 声明一个异常类在类上面加上ResponseStatus注解,就表明,在系统运行期间,抛出A ...

  9. empty,is_null,isset返回值的比较

    empty,is_null,isset返回值的比较: 变量                          empty          is_null        isset$a="& ...

  10. shrio初体验(2)Realm

    Realm:域,Shiro从从Realm获取安全数据(如用户.角色.权限),就是说SecurityManager要验证用户身份,那么它需要从Realm获取相应的用户进行比较以确定用户身份是否合法:也需 ...