import java.util.Scanner;
import org.jgroups.*;
import org.jgroups.util.*;

public class SimpleChat extends MyReceiver {
    public static void main(String[] args) throws Exception {
        new SimpleChat().start();
    } 

    private void start() throws Exception {
        JChannel channel = new JChannel();
        channel.setReceiver(this);
        channel.connect("ChatGroup");
        while (true) {
            System.out.print("> "); 
            String line = new Scanner(System.in).nextLine();
            if (line.startsWith("exit"))
                break; 
            channel.send(new ObjectMessage(null, line));
        }
        channel.close();
    }

    public void receive(Message msg) {
        System.out.println(msg.getSrc() + ": " + msg.getObject()); 
    }
}