后台维护界面展现:
人员的组织及其所在群组的维护页面就不在展现下面展现客户端。
以上是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 Mapattributemap ; private String aHosturl=null; private String SUBJECT = "/pushlet/ping"; private String imSubject = null; private SystemChatEngine(String aHosturl, String subject, String imSubject, Map map) { this.aHosturl = aHosturl; this.SUBJECT = subject ; this.attributemap = map ; this.imSubject = imSubject ; } public static SystemChatEngine getInstance(String aHosturl, String subject ,String imSubject ,Map 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{ Mapattributemap = new HashMap () ; BASE64Encoder encoder = new BASE64Encoder(); String fromName = encoder.encode("jlee".getBytes("utf-8")) ; String message = java.net.URLEncoder.encode( encoder.encode( "baidu去百度查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所依赖的Id attributemap.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(); } } }