Broadcast to only one client with Atmosphere

2019-03-29 10:15发布

How do I broadcast messages from only one client to another with Atmosphere (Meteor)?I have currently this implementation based on meteor tutorial

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

I know it is maybe dumb question but I didn't find any information about this topic so I am asking here:)Thanks for any tips.

3条回答
放我归山
2楼-- · 2019-03-29 10:39

Another solution I believe : for adressing only one client, you don't need to broadcast, you may just do this:

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

where r is the resource that you can memorize in your program.

查看更多
forever°为你锁心
4楼-- · 2019-03-29 10:54
BroadcasterFactory.getDefault().lookup(atmosphereResource.uuid()).broadcast('something');
查看更多
登录 后发表回答