5

如何使用 Atmosphere (Meteor) 从一个客户端向另一个客户端广播消息?我目前有这个基于流星教程的实现

@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));
}
4

3 回答 3

3

我相信的另一种解决方案:仅针对一个客户,您不需要广播,您可以这样做:

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

其中 r 是您可以在程序中记住的资源。

于 2013-04-30T22:36:31.523 回答
3

这是他们 wiki 上的 Atmosphere 常见问题解答:https ://github.com/Atmosphere/atmosphere/wiki/Creating-private-channel-of-communication-between-Browsers

于 2013-04-24T19:47:03.763 回答
0
BroadcasterFactory.getDefault().lookup(atmosphereResource.uuid()).broadcast('something');
于 2013-05-10T06:05:33.837 回答