PhotonServer 学习
版本: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 学习的更多相关文章
- photonServer学习之连接数据库
string connectStr = "server=127.0.0.1;port=3306;database=database;user=root;pwd=root";//连接 ...
- 从直播编程到直播教育:LiveEdu.tv开启多元化的在线学习直播时代
2015年9月,一个叫Livecoding.tv的网站在互联网上引起了编程界的注意.缘于Pingwest品玩的一位编辑在上网时无意中发现了这个网站,并写了一篇文章<一个比直播睡觉更奇怪的网站:直 ...
- Angular2学习笔记(1)
Angular2学习笔记(1) 1. 写在前面 之前基于Electron写过一个Markdown编辑器.就其功能而言,主要功能已经实现,一些小的不影响使用的功能由于时间关系还没有完成:但就代码而言,之 ...
- ABP入门系列(1)——学习Abp框架之实操演练
作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...
- 消息队列——RabbitMQ学习笔记
消息队列--RabbitMQ学习笔记 1. 写在前面 昨天简单学习了一个消息队列项目--RabbitMQ,今天趁热打铁,将学到的东西记录下来. 学习的资料主要是官网给出的6个基本的消息发送/接收模型, ...
- js学习笔记:webpack基础入门(一)
之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...
- Unity3d学习 制作地形
这周学习了如何在unity中制作地形,就是在一个Terrain的对象上盖几座小山,在山底种几棵树,那就讲一下如何完成上述内容. 1.在新键得项目的游戏的Hierarchy目录中新键一个Terrain对 ...
- 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...
- 菜鸟Python学习笔记第一天:关于一些函数库的使用
2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...
随机推荐
- Linux下逻辑卷创建与管理
用虚拟机加一块硬盘后,查看硬盘状况,使用fdisk-l命令: [root@jerrybj ~]# fdisk -l Disk /dev/sda: 21.4 GB, 21474836480 bytes ...
- 服务端获取客户端html页面内容-2013-6-28-2
客户端怎么提交 整个html页面? 分析: 1>我们知道b/s模式,也知道http协议.服务端想要获取客户端的数据,客户端就 必须提交给它,服务器才能获取到. 2> ...
- [转]Ubuntu10下MySQL搭建Amoeba系列(文章索引)
一.前言(Introduction) 使用了Amoeba有一段时间了,发现官方博客:Amoeba使用指南有很多地方都是错误的,在我实战中给到一些错误的指示,所以我想写些在搭建的实战中给大家一点指引.欢 ...
- JS高程5.引用类型(6)Array类型的位置方法,迭代方法,归并方法
一.位置方法 ECMAScript5为数组实例添加了两个位置:indexOf()和 lastIndexOf().这两个方法接收两个参数:要查找的项和(可选的)表示查找起点位置的索引(如在数组[7,8, ...
- 基于Azure blob storage T级别HBase表恢复
为减少Hbase集群压力,提高性能,我们将HBase库中的数据移到另外的存储,下面记录当我需要对数据进行计算时,数据恢复的过程 目录: Azure storage explorer 工具 数据复制 元 ...
- floor()函数 向下取整 ceil()函数向上取整
floor(x) is the largest integer not greater than x , 也就是,floor(x) 返回的是小于等于x的所有整数中最大的整数,简单的说,就是去掉x的小 ...
- USACO 3.4 Raucous Rockers
Raucous Rockers You just inherited the rights to N (1 <= N <= 20) previously unreleased songs ...
- ffmpeg的安装--opencv视频处理必备
安装yasm(ffmpeg必备)wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gztar xzvf yasm-1. ...
- 关于Container With Most Water的求解
Container With Most Water 哎,最近心情烦躁,想在leetcode找找感觉,就看到了这题. 然而,看了题目半天,硬是没看懂,于是乎就百度了下,怕看到解题方法,就略看了下摘要,以 ...
- List list = new ArrayList()
方便以后扩展List是一个接口,而ArrayList 是一个类. ArrayList 继承并实现了List.List list = new ArrayList();这句创建了一个ArrayList的对 ...