亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2974 | 回復(fù): 0
打印 上一主題 下一主題

XMPP——Smack[6]離線消息和離線文件的實現(xiàn) [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2011-12-22 08:51 |只看該作者 |倒序瀏覽

1.離線消息

  openfire本身是支持離線消息的,不需要進(jìn)行額外處理,可以用spark測試下

  使用smack,其實他提供了相應(yīng)的方法

  Class OfflineMessageManager

 

  可以看下描述

 

The OfflineMessageManager helps manage offline messages even before the user has sent an available presence. When a user asks for his offline messages before sending an available presence then the server will not send a flood with all the offline messages when the user becomes online. The server will not send a flood with all the offline messages to the session that made the offline messages request or to any other session used by the user that becomes online.

 

英文退化了點,汗,大意就是,必須在發(fā)送在線信息之前去獲取離線消息 

 

剛開始沒看這個,結(jié)果在上線之后,去取,結(jié)果。。。。離線消息數(shù)量總是為零,囧

 

首先,連接,狀態(tài)要設(shè)為離線

  1. ConnectionConfiguration connConfig = new ConnectionConfiguration(serverDomain);    
  2.       
  3.   connConfig.setSendPresence(false); // where connConfig is object of .    
  4.     
  5.      connection = new XMPPConnection(connConfig);    
  6.      connection.connect();    

然后,登陸

  connection.login(userName, pwd);

 

接著,拿離線消息

  1. OfflineMessageManager offlineManager = new OfflineMessageManager(    
  2.                 Client.getConnection());    
  3.         try {    
  4.             Iterator<org.jivesoftware.smack.packet.Message> it = offlineManager    
  5.                     .getMessages();    
  6.     
  7.             System.out.println(offlineManager.supportsFlexibleRetrieval());    
  8.             System.out.println("離線消息數(shù)量: " + offlineManager.getMessageCount());    
  9.     
  10.                 
  11.             Map<String,ArrayList<Message>> offlineMsgs = new HashMap<String,ArrayList<Message>>();    
  12.                 
  13.             while (it.hasNext()) {    
  14.                 org.jivesoftware.smack.packet.Message message = it.next();    
  15.                 System.out    
  16.                         .println("收到離線消息, Received from 【" + message.getFrom()    
  17.                                 + "】 message: " + message.getBody());    
  18.                 String fromUser = message.getFrom().split("/")[0];    
  19.     
  20.                 if(offlineMsgs.containsKey(fromUser))    
  21.                 {    
  22.                     offlineMsgs.get(fromUser).add(message);    
  23.                 }else{    
  24.                     ArrayList<Message> temp = new ArrayList<Message>();    
  25.                     temp.add(message);    
  26.                     offlineMsgs.put(fromUser, temp);    
  27.                 }    
  28.             }    
  29.     
  30.             //在這里進(jìn)行處理離線消息集合......    
  31.             Set<String> keys = offlineMsgs.keySet();    
  32.             Iterator<String> offIt = keys.iterator();    
  33.             while(offIt.hasNext())    
  34.             {    
  35.                 String key = offIt.next();    
  36.                 ArrayList<Message> ms = offlineMsgs.get(key);    
  37.                 TelFrame tel = new TelFrame(key);    
  38.                 ChatFrameThread cft = new ChatFrameThread(key, null);    
  39.                 cft.setTel(tel);    
  40.                 cft.start();    
  41.                 for (int i = 0; i < ms.size(); i++) {    
  42.                     tel.messageReceiveHandler(ms.get(i));    
  43.                 }    
  44.             }    
  45.                 
  46.                 
  47.             offlineManager.deleteMessages();    
  48.         } catch (Exception e) {    
  49.             e.printStackTrace();    
  50.         }    

記得最后要把離線消息刪除,即通知服務(wù)器刪除離線消息

offlineManager.deleteMessages();

否則,下次上了消息還存在

接著,上線

 Presence presence = new Presence(Presence.Type.available);
        connection.sendPacket(presence);

 

2.離線文件

 

這個我沒實現(xiàn),汗

主要思想:開發(fā)openfire插件,攔截離線文件,將文件存到服務(wù)器上,同時在數(shù)據(jù)庫里開一張表,存儲文件信息

               當(dāng)用戶上線時,查表,若是有,根據(jù)路徑,拿了發(fā)送

當(dāng)然,大家可以谷歌下是否有相應(yīng)的插件,時間緊迫,我倒是沒找著

 

 

 

到這里,大概就這些了,對了,還擴(kuò)展了個視頻音頻聊天,不過使用的是JMF,點對點的,本來打算使用jingle的,結(jié)果連API文檔都沒找到,暈死

您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP