WCF 第十二章 对等网 System.Net.PeerToPeer.Collaboration
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.PeerToPeer.Collaboration;namespace PeerChat
{public class PeerChatApplication{private static PeerApplication PeerChatPeerApplication;private static Guid PeerChatAppId = new Guid("4BC6F59E-124E-4e75-8CD9-BB75BCA78CA8");private static string PeerChatDescription = "A sample peer networking application";static PeerChatApplication(){PeerChatPeerApplication =new PeerApplication(PeerChatAppId,PeerChatDescription,null,System.Windows.Forms.Application.ExecutablePath,null,PeerScope.All);}public static void Register(){PeerApplicationCollection peerAppsColl = PeerCollaboration.GetLocalRegisteredApplications(PeerApplicationRegistrationType.AllUsers);//You gotta love LINQ! It is so cool!IEnumerable<PeerApplication> findPeerApp =from peerApp inPeerCollaboration.GetLocalRegisteredApplications(PeerApplicationRegistrationType.AllUsers)where peerApp.Id == PeerChatAppIdselect peerApp;if (findPeerApp.Count<PeerApplication>() != 0){PeerCollaboration.UnregisterApplication(PeerChatPeerApplication,PeerApplicationRegistrationType.AllUsers);}PeerCollaboration.RegisterApplication(PeerChatPeerApplication,PeerApplicationRegistrationType.AllUsers);}public static void UnRegister(){PeerCollaboration.UnregisterApplication(PeerChatPeerApplication,PeerApplicationRegistrationType.AllUsers);}}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.PeerToPeer.Collaboration;namespace PeerChat
{public class PeopleNearMeHelper{public PeopleNearMeHelper(){PeerCollaboration.SignIn(PeerScope.All);}public PeerNearMeCollection PeopleNearMe{get{return PeerCollaboration.GetPeersNearMe();}}}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.PeerToPeer.Collaboration;
using System.IO;namespace PeerChat
{public class InvitationHelper{private static PeerApplication PeerChatPeerApplication;private static Guid PeerChatAppId = new Guid("4BC6F59E-124E-4e75-8CD9-BB75BCA78CA8");private static string PeerChatDescription = "A sample peer networking application";static InvitationHelper(){PeerChatPeerApplication =new PeerApplication(PeerChatAppId,PeerChatDescription,null,System.Windows.Forms.Application.ExecutablePath,null,PeerScope.All);}public static PeerInvitationResponseType Invite(PeerNearMe personTo,Guid chatId,Guid meshPassword){byte[] data;using (MemoryStream ms = new MemoryStream()){using (StreamWriter sw = new StreamWriter(ms)){sw.Write(chatId.ToString());sw.WriteLine();sw.Write(meshPassword.ToString());}data = ms.ToArray();}PeerInvitationResponse response =personTo.Invite(PeerChatPeerApplication,"You are being invited to chat.", data);return response.PeerInvitationResponseType;}public static void InviteAsync(PeerNearMe personTo,Guid chatId, Guid meshPassword){byte[] data;using (MemoryStream ms = new MemoryStream()){using (StreamWriter sw = new StreamWriter(ms)){sw.Write(chatId.ToString());sw.WriteLine();sw.Write(meshPassword.ToString());}data = ms.ToArray();}object userToken = Guid.NewGuid();personTo.InviteAsync(PeerChatPeerApplication,"You are being invited to chat.", data, userToken);}public static bool IsLaunched{get{return (PeerCollaboration.ApplicationLaunchInfo != null) && (PeerCollaboration.ApplicationLaunchInfo.Data != null)}}public static Guid ChatId{get{Guid chatId;using (MemoryStream ms = new MemoryStream(PeerCollaboration.ApplicationLaunchInfo.Data)){using (StreamReader sr = new StreamReader(ms)){string chatIdString = sr.ReadLine();string meshPassword = sr.ReadLine();chatId = new Guid(chatIdString);}}return chatId;}}public static Guid MeshPassword{get{Guid meshPassword;using (MemoryStream ms = new MemoryStream(PeerCollaboration.ApplicationLaunchInfo.Data)){using (StreamReader sr = new StreamReader(ms)){string chatIdString = sr.ReadLine();string meshPasswordString = sr.ReadLine();meshPassword = new Guid(meshPasswordString);}}return meshPassword;}}}
}
转载于:https://www.cnblogs.com/danielWise/archive/2011/05/26/2057735.html
WCF 第十二章 对等网 System.Net.PeerToPeer.Collaboration相关推荐
- WCF 第十二章 对等网
很多开发人员在创建分布式应用程序时会考虑客户端-服务端或者n-层结构模型.另外一个通常会被忽略的创建分布式应用程序的方案是点到点(P2P)模型.大多数流行的互联网应用程序中的一部分,包含即时通信,游戏 ...
- WCF 第十二章 对等网 使用自定义绑定实现消息定向
当使用对等传输信道时会有一个常见的错误,就是认为它支持在一个对等网状网络间定向通信.消息定向意味着一条消息可以在一个对等网状网络中通过跨越一个网状网络将其传播到目的端(这就是路由的原理)来发送到特定节 ...
- css层叠样式表基础学习笔记--第十二章 我要自学网首页实战
第十二章 我要自学网首页实战 12-01 页面分析 12-02 工作准备 12-03 搜索区块页面结构 12-04 导航条布局 12-05 幻灯片布局 12-06 公告栏布局 12-07 远程培训班布 ...
- 【信息系统项目管理师】第二十二章 信息系统安全管理(考点汇总篇)
[信息系统项目管理师]第二十二章 信息系统安全管理(考点汇总篇) 考点分析与预测 信息安全为高级科目独有的章节,在第三版教材中有66页的内容.需要掌握的知识点非常多,且知识点非常散,在考试中上午一般考 ...
- 第十二章_网络搭建及训练
文章目录 第十二章 网络搭建及训练 CNN训练注意事项 第十二章 TensorFlow.pytorch和caffe介绍 12.1 TensorFlow 12.1.1 TensorFlow是什么? 12 ...
- Linux云计算【第一阶段】第十二章:网络管理、进制及SSH管理与攻防
第十二章:网络管理及SSH管理与攻防 [重难点] 一.网络发展概述 局域网 城域网 广域网 基本网络协议 客户端与服务器的概念 从客户端到服务器的经过 No.1 客户端与服务器的概念 客户端: 即表示 ...
- 鸟哥的Linux私房菜(服务器)- 第二十二章、邮件服务器: Postfix
第二十二章.邮件服务器: Postfix 最近更新日期:2011/08/10 在这个邮件服务器的架设中,我们首先谈论 Mail 与 DNS 的重要相关性,然后依序介绍 Mail Server 的相关名 ...
- 第十二章-硬盘介绍和磁盘管理 随堂笔记
第十二章-硬盘介绍和磁盘管理 本节所讲内容: 12.1 SAS-SATA-SSD-SCSI-IDE硬盘讲解 12.2 磁盘分区工具和挂载 12.3 实战扩展swap分区 12.1 SAS-SATA-S ...
- 疯狂JAVA讲义---第十二章:Swing编程(五)进度条和滑动条
http://blog.csdn.net/terryzero/article/details/3797782 疯狂JAVA讲义---第十二章:Swing编程(五)进度条和滑动条 标签: swing编程 ...
最新文章
- 剑指offer:面试题28. 对称的二叉树
- MySQL 8.0 正式版 8.0.11 发布:比 MySQL 5.7 快 2 倍
- 【spring boot2】第2篇:配置文件YAML语法
- 计算机函数select,请问关于select函数的操作程序?
- 华为交换机linux版本号,Cisco和华为交换机常用配置命令总结
- java properties 保存_Java 读写Properties配置文件
- 免费mysql空间_php+mysql免费空间
- 设置线程当天十二点执行_这份JAVA多线程笔记真的是细节满满,几乎全是你工作能用到的干货...
- java.sql.SQLException: Value'0000-00-00'异常解决办法
- VMware虚拟机与Windows文件共享
- Doris之Rollup 与查询
- Localdatetime的坑
- 【LeetCode】【字符串】题号:*657. 机器人能否返回原点
- 盒马销量预测核心算法的技术演进
- bootstrap 检验 法 原理_三种中介效应检验方法及操作步骤 - spssau
- Vue 使用Excel表格导入导出
- IT行业都有哪些职位,初学者(0基础,新人)该如何选择,才能够快速进入这个行业?... 1
- 笔记本电脑计计算机硬盘分区,笔记本电脑如何分区,小编教你笔记本电脑如何分区...
- ORB-SLAM2学习笔记——BundleAdjustment函数
- JS 对象直接量方法创建对象
热门文章
- Vue中的join(),reverse()与 split()函数
- 如何选择分布式事务形态
- Lock应用之 读写锁
- Android设置无title报错
- LNMP3.0一键安装
- http://zhcsmx22.blog.51cto.com
- 02 | 纵览全局:把握 Netty 整体架构脉络
- 分子模拟的理论与实践_基于分子模拟的数据驱动发现流体力学宏观方程
- https://akaedu.github.io/book/ch32s02.html
- java 多线程 关键字_Java多线程常用的几个关键字