EXT(dwr) Web在线聊天系统群聊和私聊的实现
来源:互联网 发布:mac使用fontawesome 编辑:程序博客网 时间:2024/05/16 07:28
群聊:使用推送技术向所有在线用户发送消息
WebContext wctx = WebContextFactory.get();String currentPage = wctx.getCurrentPage();ScriptBuffer script = new ScriptBuffer();script.appendScript("receivePublicMessages(").appendData(list).appendScript(");");Collection Sessions = wctx.getScriptSessionsByPage(currentPage);for (Iterator<ScriptSession> it = Sessions.iterator(); it.hasNext();) {((ScriptSession) (it.next())).addScript(script);}
私聊:实现定向推送
1.在加载聊天页面时将用户信息写入ScriptSession中
页面载入是掉init(),然后在init中调用服务器的方法,内容如下
HttpSession httpSession = WebContextFactory.get().getSession();httpSession.setAttribute("scriptSession", thisSession.hashCode());if (thisSession.getAttribute("user") == null) {// 保存该用户地scriptSessionthisSession.setAttribute("user", httpSession.getAttribute("userSession"));}
2.在发送时候,遍历当前的所有ScriptSession,找到需要发送的人。
ScriptSession currSession = wctx.getScriptSession();// 获取当前会话的ScriptSessionString currentPage = wctx.getCurrentPage();ScriptBuffer script = new ScriptBuffer();script.appendScript("receivePrivateMessages(").appendData(list).appendScript(");");Collection Sessions = wctx.getScriptSessionsByPage(currentPage);// 获取引用当前页面的所有ScriptSessionfor (Iterator it = Sessions.iterator(); it.hasNext();) {ScriptSession otherSession = (ScriptSession) it.next();OnlineUserTO currUser = (OnlineUserTO) (otherSession.getAttribute("user"));if (currUser == null || currUser.getId() == null) {continue;}if (receiverId.equals(currUser.getId().toString())) {otherSession.addScript(script);}}currSession.addScript(script);
3.由于每次用户刷新浏览器,都会创建一个新的ScriptSession,所以需要及时pass掉过时的ScriptSession(虽然不做,基本功能也能实现,基于存储考虑)
- EXT(dwr) Web在线聊天系统群聊和私聊的实现
- Ext 在线实时聊天系统的开发,有源码包,实现了实时更新在线用户列表和群聊
- Web 实现在线聊天的系统 强烈推荐
- dwr实现web单聊
- 基于Web在线聊天系统初步构想。
- 简单在线聊天系统的实现(初步)
- 简单在线聊天系统的实现(完成)
- 基于webSocket实现的一对一在线聊天系统
- 基于Bmob的在线群聊之群聊天的实现
- web在线实时聊天的一种方法
- DWR反向Ajax的一个简单Web聊天
- DWR反向Ajax的一个简单Web聊天
- DWR反向Ajax的一个简单Web聊天
- node-socket实现web的即时聊天系统
- Ext+dwr的使用
- 基于JavaSE的在线聊天系统
- HuaXinIM聊项目阶段总结四(在线用户列表与聊天窗口的实现)
- 网站在线聊天系统
- 单片机串口通信中换行的两种方法
- skyeye学习之s3c2410的串口通信
- Linux内核线程
- 给定N位数,去掉K位数,得到的N-K位数中最小的那个数?
- HTTPS重定向到HTTP
- EXT(dwr) Web在线聊天系统群聊和私聊的实现
- Filter的使用问答
- VECTORSoftware强势进入中国市场
- 老程序员十年生涯黯然总结
- 5分钟理解JavaScript中this用法
- 八条设计多线程程序的简单规则
- 模仿android4.0的 通知栏 listview 滑动删除 item ,有滑动动画。
- Python sorting list of dictionaries by multiple keys
- UITableView 关键操作