2013-04-22 38 views
5

如何播放從只有一個客戶端的消息到另一個大氣層(流星)?我已經目前這個實現基於流星教程廣播只有一個客戶端與大氣

@Override 
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { 
    Meteor.build(req).addListener(new AtmosphereResourceEventListenerAdapter()); 
} 

@Override 
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException { 
    String body = req.getReader().readLine().trim(); 
    //some DAO lookups - here I would like to say I want to broadcast only to concrete client 
    BroadcasterFactory.getDefault().lookup(DefaultBroadcaster.class, "/*").broadcast(UserDAO.getInstance().getUser(name)); 
} 

我知道這也許是愚蠢的問題但我沒有找到關於這個主題的任何信息,所以我在這裏問:)謝謝你的任何提示。

回答

3

另一種解決方案,我相信:對於adressing只有一個客戶,你不需要廣播,你可能只是這樣做:

 try 
    { 
     r.getResponse().write(message); 
    } 
    catch(IllegalStateException e) 
    { 
     logger.error("Could not send message through atmosphere " + userId); 
    } 

其中r是您可以記憶在程序中的資源。

+0

我將'AtmosphereResource'保存在另一個類的靜態地圖中。然後遍歷它們並調用你顯示的'write'方法,但客戶端什麼都沒有收到。 – kiltek 2017-08-08 10:03:28

+0

@kiltek它已經有一段時間了,但很可能這個解決方案有點像一個http會話。所以你不能再保留它,只是在「會話」中使用它 – unludo 2017-08-08 14:23:19

0
BroadcasterFactory.getDefault().lookup(atmosphereResource.uuid()).broadcast('something'); 
+0

這已被棄用,現在完全拋出。 – kiltek 2017-08-08 09:59:38

相關問題