How to Create an Multicast Client/Server with JGroups

Client

import static java.lang.System.out;

import org.jgroups.JChannel;
import org.jgroups.Message;
import org.jgroups.ReceiverAdapter;

public final class JGroupsClient {

  public static void main(final String[] args) throws Exception {
    final JChannel chan = new JChannel();

    chan.setReceiver(new ReceiverAdapter() {

      public void receive(final Message msg) {
        out.println(msg);
      }

    });
  }

}

Server

import org.jgroups.JChannel;
import org.jgroups.Message;

public final class JGroupsServer {

  public static void main(final String[] args) throws Exception {
    final JChannel chan = new JChannel();

    chan.connect("SampleCluster");
    
    final Message msg = new Message(null, "Simples Assim");

    while (true)
      chan.send(msg);

  }

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s