TaidouChatServerClient(客户端)
来源:互联网 发布:centos ftp客户端命令 编辑:程序博客网 时间:2024/06/06 04:17
需添加引用:"ExitGamesLibs.dll" "Photon.SocketServer.dll" "PhotonHostRuntimeInterfaces.dll"" Photon3DotNet.dll"
using ExitGames.Client.Photon;
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TaidouChatServerClient
{
class ChatServerListener : IPhotonPeerListener //实现 接口IPhotonPeerListener
{
public bool isConnected = false;
//进行一些Debug的回掉和Debug的输出 日志的输出
public void DebugReturn(DebugLevel level, string message){
}
//服务器端进行回应时,服务器端进行调用的 OnEvent和OnOperationResponse
public void OnEvent(EventData eventData)
{
}
public void OnMessage(object messages)
{
}
//得到服务器端的响应
public void OnOperationResponse(OperationResponse operationResponse)
{
Dictionary<byte, object> dict = operationResponse.Parameters;//.Parameters就是我们的字典参数
object v = null;
dict.TryGetValue(1, out v);
Console.WriteLine("Get value from server:" + v.ToString());
}
//表示客户端和服务器端连接状态发生变化时 调用的
public void OnStatusChanged(StatusCode statusCode)
{
Console.WriteLine(statusCode);
switch (statusCode)
{
case StatusCode.Connect:
isConnected = true;
Console.WriteLine("Connect .");
break;
}
}
}
//用peer向服务器端发起请求,用ChatServerListener(也就是listener)去响应服务器端的请求
class Program
{
static void Main(string[] args)
{
ChatServerListener listener = new ChatServerListener(); 创建一个监听器listener
PhotonPeer peer = new PhotonPeer(listener, ConnectionProtocol.Tcp); /*利用PhotonPeer与服务器端进行交互 监听类是用来监听服务器返回的一些方法,返回的一些消息的,需要一个IPhotonPeerListener,所以创建一个监听类ChatServerListener 实现接口IPhotonPeerListener*/
peer.Connect("127.0.0.1:4530", "ChatServer");//连接服务器,需要时间
Console.WriteLine("Connecting ... ");
while (listener.isConnected == false)
peer.Service(); //向服务器发起请求
Dictionary<byte, object> dict = new Dictionary<byte, object>();
dict.Add(1, "username");
dict.Add(2, "password");
peer.OpCustom(1, dict, true);//OpCustom用来向服务器端发起一个请求 true表示发起的请求可靠
//需要一些时间,故后边不能立即跟peer.Service();
while (true)
{
peer.Service();
}
}
}
}
0 0
- TaidouChatServerClient(客户端)
- 配置CAS客户端(php 客户端 )
- C#服务器端与客户端通信(客户端)
- 智能客户端(SmartClient)
- 智能客户端(SmartClient)
- 浏览器(客户端)缓存
- SVN使用手册(客户端)
- UDP通讯(客户端)
- TCP通讯(客户端)
- CFSocket(客户端)
- AndroidFtp客户端(二)
- FTP客户端(改进)
- 客户端JavaScript(一)
- NIO客户端(多线程)
- 搭建GCM(客户端)
- Navicate (数据库客户端)
- Zookeeper(二)客户端
- 客户端(浏览器)缓存
- LeetCode 452. Minimum Number of Arrows to Burst Balloons
- Leetcode-80. Remove Duplicates from Sorted Array II
- s3c2440- led驱动分析及其测试程序
- 计算机网络总结
- 非常弹的球
- TaidouChatServerClient(客户端)
- 数据库shard中间件对比,以及sharding-jdbc 实现原理分析
- C#学习笔记(一)C#程序结构
- 欢迎使用CSDN-markdown编辑器
- PHP及其微信开发(学习之路 六)
- 网站安全之存储型跨站脚本编制
- 单例模式示例
- 最长严格上升子序列O(nlogn)算法
- SAP HANA SQL合并多行操作