您好,欢迎光临本网站![请登录][注册会员]  
文件名称: C#网页版+客户端版聊天软件
  所属分类: C#
  开发工具:
  文件大小: 3mb
  下载次数: 0
  上传时间: 2015-04-05
  提 供 者: wang1*****
 详细说明: C#网页版+客户端版聊天软件源码分享(C#+长连接+Sqllite数据库实现) 今天我给大家分享一个聊天程序的源码。 网页版加客户端版并存,可以互通 我相信对大家学习和扩展这一块知识是很有用的。 我们先来看下软件结构 一个Web版一个网页版,而客户端是连接的网页的 http://localhost:53947/wwwroot/Lesktop 这个路径 http://localhost:53947/wwwroot/这一部分是网页的地址,大家可以根据自己配置情况进行修改 然后浏览一下Default.aspx页面如下 这是负面版的,客户端的也是一样的,我们先来注册 一个账户 在这里我们注册两个账户还有一个是text用来聊天对话使用 注册的方法是一样的我就不多说了。 下面登录第一个账户看看 这是登录后的效果。 单击聊天室 然后我们再登录另外一个账户text 好了大家应该能看到效果了吧。 然后咱们再发个“你好” 收到了吧,再回复一个 对就是这个效果, 再来看看桌面版的 刚才的消息都在 这是桌面版的效果。 大家感觉怎么样。 我感觉大家可以在这个基础之上进行扩展,最少可以看看他的实现思路 源码 分享给大家了 sufeinet.com即时通信_云骞.zip (3.25 MB, 下载次数: 1078) ReceiveResponsesHandler 类,这个主要是用来接收和维护长连接的 实现长连接的两个重要来代码预览 [C#] 纯文本查看 复制代码 ? 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 using System; using System.Collections.Generic; using System.Collections; using System.Text; using System.Web; using System.Xml; using System.Threading; namespace Core { public class ReceiveResponsesHandler : IHttpAsyncHandler { public ReceiveResponsesHandler() { } HttpContext m_Context = null; IAsyncResult IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) { m_Context = context; string sessionId = context.Request.Params["SessionID"]; string clientVersion = context.Request.Params["ClientVersion"]; string serverVersion = context.Request.Params["ServerVersion"]; ResponsesListener asyncResult = new ResponsesListener(sessionId, cb, extraData); try { if (serverVersion != ServerImpl.Instance.Version) throw new IncompatibleException(); if (!String.IsNullOrEmpty(clientVersion) && clientVersion != "1.0.1.7") throw new IncompatibleException(); string username = ServerImpl.Instance.GetUserName(context); if (string.IsNullOrEmpty(username)) throw new UnauthorizedException(); AccountState state = SessionManagement.Instance.GetAccountState(username); if (state.Receive(sessionId, asyncResult)) { ThreadPool.QueueUserWorkItem(asyncResult.Complete); } } catch (Exception ex) { asyncResult.Cache(Utility.RenderHashJson("IsSucceed", false, "Exception", ex)); ThreadPool.QueueUserWorkItem(asyncResult.Complete); } return asyncResult; } void IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) { //将消息发送到客户端 ResponsesListener asyncResult = result as ResponsesListener; asyncResult.Send(m_Context); } void IHttpHandler.ProcessRequest(HttpContext context) { } bool IHttpHandler.IsReusable { get { return true; } } } class UnauthorizedException : Exception { } class IncompatibleException : Exception { } } SendCommandHandler是用来发送消息的 [C#] 纯文本查看 复制代码 ? 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 using System; using System.Collections.Generic; using System.Collections; using System.Text; using System.Web; using System.Xml; using System.Threading; using System.Web.SessionState; using System.Reflection; namespace Core { public class SendCommandHandler : IHttpHandler { void IHttpHandler.ProcessRequest(HttpContext context) { Exception error = null; String data = null; try { System.IO.Stream inputStream = context.Request.InputStream; Byte[] buffer = new Byte[inputStream.Length]; inputStream.Read(buffer, 0, (int)inputStream.Length); string content = context.Request.ContentEncoding.GetString(buffer); XmlDocument doc = new XmlDocument(); doc.LoadXml(content); String[] handlerInfo = doc.DocumentElement.GetAttribute("Handler").Split(new char[] { ' ' }); String cmdId = doc.DocumentElement.GetAttribute("ID"); String sessionId = doc.DocumentElement.GetAttribute("SessionID"); bool isAsyn = Boolean.Parse(doc.DocumentElement.GetAttribute("IsAsyn")); Assembly assembly = Assembly.Load(handlerInfo[0]); Type handlerType = assembly.GetType(handlerInfo[1]); ConstructorInfo ctor = handlerType.GetConstructor(new Type[] { typeof(HttpContext), typeof(String), typeof(String), typeof(String) }); CommandHandler handler = ctor.Invoke(new object[] { context, sessionId, cmdId, doc.DocumentElement.InnerXml }) as CommandHandler; if (isAsyn) { ThreadPool.QueueUserWorkItem(handler.Process); } else { data = handler.Process(); } } catch (Exception ex) { error = ex; } if (error == null) { context.Response.Write(Utility.RenderHashJson("IsSucceed", true, "Data", new JsonText(data))); } else { context.Response.Write(Utility.RenderHashJson("IsSucceed", false, "Exception", error)); } } bool IHttpHandler.IsReusable { get { return true; } } } public abstract class CommandHandler { HttpContext _context = null; public HttpContext Context { get { return _context; } } String _data; public String Data { get { return _data; } } String _id; public String CommandID { get { return _id; } } String _sessionId; public String SessionID { get { return _sessionId; } } public String UserName { get { return ServerImpl.Instance.GetUserName(_context); } } public CommandHandler(HttpContext context, String sessionId, String id, String data) { _context = context; _data = data; _id = id; _sessionId = sessionId; } public abstract void Process(object data); public abstract String Process(); } } 大家想看对应关系直接看Webconfig文件 [C#] 纯文本查看 复制代码 ? 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 这样写的目的和好处大家要吧看我的文章 http://www.sufeinet.com/thread-7784-1-1.html 好了就到这里吧,大家有什么问题回复我吧。 感觉还可以的就给你支持 ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: 聊天
 输入关键字,在本站1000多万海量源码库中尽情搜索: