Creating private channel of communication between Browsers - Atmosphere/atmosphere GitHub Wiki

If you want to create a channel of communication between two Browsers (aka user), all you need to do is to create a Broadcaster:

Broadcaster privateChannel = BroadcasterFactory.getDefault().lookup("/private", true);

Next you need to associate the AtmosphereResource, who represent the browser/user to that Broadcaster

privateChannel
   .addAtmosphereResource(atmosphereResource_browser1)
   .addAtmosphereResource(atmosphereResource_browser2);

You are now ready to broadcast to both browsers/users privately

privateChannel.broadcast("hello");

The hello message will be delivered to both browsers/users.

You can also create Broadcaster for one way communication, e.g from Browser 1 to Browser 2 by doing

Broadcaster toBrowser2 = BroadcasterFactory.getDefault().lookup("/private", true);
toBrowser2.addAtmosphereResource(atmosphereResource_browser2);
toBrowser2.broadcast("Hello from browser 1")

Alternatively, you can use the privateChannel and broadcast to a subset:

privateChannel.broadcast("hello from browser1",atmosphereResource_browser2);