import com.ezjavabeans.ezmulticast.*; import java.util.*; import java.io.*; /** This example shows how to multicast objects.*/ public class MulticastObject implements EzMulticastEventListener{ EzMulticast ezMulticast = new EzMulticast(); //############################################################################ public MulticastObject (){ try{ //Sets the properties of EzMulticast. ezMulticast.setGroupAddress("230.0.0.1"); ezMulticast.setGroupPort(4446); ezMulticast.setSerialKey("Sets the Serial Key to activate the full version."); ezMulticast.addEzMulticastEventListener(this); ezMulticast.setActive(true); }catch(EzMulticastException ex){ System.out.println(ex.getMessage()); } }//MulticastObject()---------------------------------------------------------- //############################################################################ /** Multicasting a Object. */ public void sendObject(){ try{ //You can send any kind of object that implements Serializable. //In this example, we send the current date. Date date = new Date(System.currentTimeMillis()); //Serialize the Date object. ByteArrayOutputStream bao = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bao); oos.writeObject(date); //Multicast the object. ezMulticast.send(bao.toByteArray()); }catch(IOException ex){ System.out.println(ex.getMessage()); }catch(EzMulticastException ex){ System.out.println(ex.getMessage()); } }//sendObject()--------------------------------------------------------------- //############################################################################ /** Reception of the object via EzMulticast */ public void dataIn(EzMulticastDataInEvent e){ try{ ByteArrayInputStream bai = new ByteArrayInputStream(e.data); ObjectInputStream ois = new ObjectInputStream(bai); Object o = ois.readObject(); if(o instanceof Date){ System.out.println("Time receive : " + ((Date)o).getTime()); //You can format the date the way you want here... } }catch(Exception ex){ System.out.println(ex.getMessage()); } }//dataIn()------------------------------------------------------------------- }