You simply need to create a shared context e.g. topic on the server for each group of users. Sender publishes to the topic. Listeners are subscribed to the topic. It is a simple matter of the server receiving a message; mapping to the topic; and sending the message to the subscribers of that topic.
Main design issue is to determine if you need static or dynamic topics. In other words, in static topics, the server is given a (static) list of topics (via say a config file). In dynamic variant, you would need to provide the mechanism for dynamic group formation.
Second issue is topic durability. Can users of the group drop out (of net) and then re-establish connection and get messages that they missed when disconnected? etc.
p.s. there are a variety of messaging frameworks, from JMS to AMPQ to PubSubHub for Java so you can probably highly leverage existing code. But it really can be something as simple as pushing messages to server via REST calls. Receivers would need to either poll the server (via an analog REST call) or maintain a connection for the server to push to them. (The latter is probably not a very good idea if you expect a lot of users.)
[final edit: If you are going to roll your own, I strongly suggest you take a look at Redis. It should be easy for you to quickly prototype something that way.]