Outubro 2008
Prof. Ismael H. F. Santos -  ismael@tecgraf.puc-rio.br                                                          2
Multicast peer joins a group and sends and receives datagrams
import java.net.*;
import java.io.*;
public class MulticastPeer{
    public static void main(String args[]){
     // args give message contents & destination multicast group (e.g. "228.5.6.7")
    MulticastSocket s =null;
    try {
       InetAddress group = InetAddress.getByName(args[1]);
       s = new MulticastSocket(6789);
       s.joinGroup(group);
       byte [] m = args[0].getBytes();
       DatagramPacket messageOut =  new DatagramPacket(m, m.length,
                                                                                                 group, 6789);
       s.send(messageOut);
  
    // this figure continued on the next slide