Search code examples
javaatmosphere

atmosphere p2p chat


I would like to know if it is possible to create web based chat with Atmosphere Framework that would work for p2p. In Atmosphere examples there are chat examples that broadcast message to all listeners that are currently subscribed. I would like to deliver message to particular user for which it will be intended for.


Solution

  • Its pretty simple .Lets just say you want only user A to be notified when user B sends a message.You just need to add the atmosphere resource representing user A to user B's broadcaster.All you need to do is to have a Broadcaster per user.Then use BroadcasterFactory to get the particular broadcaster.Eg.

    Broadcaster broadcasterUserA = BroadcasterFactory.getDefault().get("A");
    Broadcaster broadcasterUserB = BroadcasterFactory.getDefault().get("B"); 
    

    and then add A's AtmosphereResource to B's broadcaster.

    broadcasterUserB.addAtmospherResource(//here put A's atmosphere resource//);
    

    Or you could get the A's broadcaster like

    BroadcasterFactory.getDefault().lookup("A",true).broadcast("message from B");
    

    Hope this helps.