pushlet实现webQQ即时通信
后台维护界面展现:
??????????????????????????????????????????????????????????????? ?后台首页
?
?
?
????????????????????????????????????????????????????? 账户及其人员列表
?
人员的组织及其所在群组的维护页面就不在展现下面展现客户端。
?
???????????????????? 用户登录
?
?????????????? 鼠标悬停
?
?
????????????????? 维护状态
?
?
???????????? ????? 鼠标右键
?
?
?????????????????????????????????????????????? 查看人员信息
?
?
?
??????????????????????????????????????????? 查看聊天记录
?
?
???? ???????????????????????????????????? 维护个人资料
?
?
?
?????????????????????????????????????????? 聊天窗口
?
?
?
???????????????????????????????????????? 互相附件传送
?
?
???????????????? IM实现消息提醒
?
?????? ?????????????????????????? 实现群组之间的聊天
?
以上是IM(即时通信)一些基本功能的简介,好了就先到此为止吧。。。。。
在Pushlet的应用方面希望可以与大家相互交流,互相学习。
?
?
?
?
JavaScript两种发送消息的方式不用多说
1、Ajax保持心跳的即时通信
2、往前台输送HTML的即时通信
?
下面贴Java实现即时通信的代码
package com.jlee.im;import java.util.Map;import nl.justobjects.pushlet.client.PushletClient;import nl.justobjects.pushlet.client.PushletClientListener;import nl.justobjects.pushlet.core.Event;import nl.justobjects.pushlet.core.Protocol;public class SystemChatEngine extends Thread implements PushletClientListener, Protocol {//private static SystemChatEngine systemChatEngine = new SystemChatEngine("http://localhost:8888/im/pushlet.srv");private static SystemChatEngine engine = null ;private PushletClient pushletClient;private Map<String ,String> attributemap ;private String aHosturl=null;private String SUBJECT = "/pushlet/ping";private String imSubject = null;private SystemChatEngine(String aHosturl, String subject, String imSubject, Map<String ,String> map) {this.aHosturl = aHosturl;this.SUBJECT = subject ;this.attributemap = map ;this.imSubject = imSubject ;}public static SystemChatEngine getInstance(String aHosturl, String subject ,String imSubject ,Map<String ,String> map){if(engine==null){engine = new SystemChatEngine(aHosturl,subject,imSubject,map) ;engine.start() ;}return engine ;}public void run() {try {pushletClient = new PushletClient(aHosturl);pushletClient.setDebug(false);pushletClient.setUid(attributemap.get("uid")) ;pushletClient.join();pushletClient.listen(this, Protocol.MODE_PULL,SUBJECT);System.out.println("pushletClient started");pushletClient.publish(imSubject, attributemap);} catch (Exception e) {e.printStackTrace();return;}}/** Error occurred. */public void onError(String message) {System.out.println(message);}/** Abort event from server. */public void onAbort(Event theEvent) {}/** Data event from server. */public void onData(Event theEvent) {String meSessionID = theEvent.getField("uid");}/** Heartbeat event from server. */public void onHeartbeat(Event theEvent) {}public void onRefresh(Event theEvent) {}public void onJoinListenAck(Event theEvent) {String meSessionID = theEvent.getField("uid");}public void onListenAck(Event theEvent) {String meSessionID = theEvent.getField("uid");}/** * @return pushletClient *///public static PushletClient getPushletClient() {//while(systemChatEngine.pushletClient==null){}//return systemChatEngine.pushletClient;//}/** Main program. *///public static void main(String args[]) {//systemChatEngine.start();//}}
?
?
?
package com.jlee.im;import java.util.HashMap;import java.util.Map;import sun.misc.BASE64Encoder;public class WebIMClient {static SystemChatEngine engine = null ;public void sendTask()throws Exception{Map<String ,String> attributemap = new HashMap<String, String>() ;BASE64Encoder encoder = new BASE64Encoder();String fromName = encoder.encode("jlee".getBytes("utf-8")) ;String message = java.net.URLEncoder.encode(encoder.encode("<a href='#' title='http://www.baidu.com' name='alabel'>baidu</a>去百度查IM".getBytes("utf-8"))) ;String remark = encoder.encode("备注".getBytes("utf-8")) ;String title = encoder.encode("主题1".getBytes("utf-8")) ;String msgType = encoder.encode("类型1".getBytes("utf-8")) ;String msgGroup = encoder.encode("self".getBytes("utf-8")) ;//self(表示消息来自系统OA)或者other(消息来自其他系统)attributemap.put("uid" ,"728852348a9f4c219f9666facef19356") ;//该字段不会进入数据库,只是充当Pushlet所依赖的Idattributemap.put("fromId", "728852348a9f4c219f9666facef19356") ;attributemap.put("fromName", fromName) ;attributemap.put("toId", "86523b57993048a0b82bd06772e432dd") ;attributemap.put("toGroupId", null) ;attributemap.put("message", message) ;attributemap.put("remark", remark) ;attributemap.put("title", title) ;attributemap.put("msgType", msgType) ;attributemap.put("msgGroup", msgGroup) ;engine = SystemChatEngine.getInstance("http://localhost:8888/im/pushlet.srv", "/pushlet/ping,/task/warn","/task/warn", attributemap) ;}public static void main(String[] args) {WebIMClient client = new WebIMClient() ;try {client.sendTask() ;} catch (Exception e) {e.printStackTrace();}}}
?
1 楼 need_faith 2011-10-08 不错的文章 2 楼 xumin198908 2012-03-13 学习了!!!!!!