EzMulticast 1.0 is used to transmit a single message to a select group of recipients.
EzMulticast acts as a server and a client to send and receive UDP datagrams.
Price : $35.00


[Try it!] [Buy it!]
[Methods] [View Javadoc] [Download Javadoc] [Example 1] [Example 2]

Note : The evaluation version is limited to sending/receiving one message every 3 seconds.

Principal methods
Method Name Description
EzMulticast()
Creates a new instance of EzMulticast.
send(byte[] message) Sends a datagram packet to the remote group.
setActive(boolean a) Enables or disables sending and receiving data.
setGroupAddress(String s) Sets the address of the group.
setGroupPort(int port) Sets the group port.
setSerialKey(String key)
Sets the Serial Key used to activate the full version.


Example 1: SimpleChat.java

import java.awt.event.*;
import com.ezjavabeans.ezmulticast.*;
import javax.swing.*;


/** This example shows how to create a simple 
* chat with EzMulticast.*/
public class SimpleChat implements EzMulticastEventListener{ EzMulticast ezMulticast = new EzMulticast(); //Swing composants JFrame frame = new JFrame(); JPanel panel = new JPanel(); JLabel labelRcv = new JLabel(); JLabel labelMsg = new JLabel(); JTextField textRcv = new JTextField(); JTextField textMsg = new JTextField(); JButton buttonSend = new JButton(); public static void main(String[] args) { SimpleChat sc = new SimpleChat(); sc.jbInit(); sc.frame.show(); } /** Initialization of all the composants */ private void jbInit(){ try{ //Sets the Group Address for multicasting ezMulticast.setGroupAddress("230.0.0.1"); //Sets the Group port for multicasting ezMulticast.setGroupPort(4446); //Registers to receive Data and errors from EzMulticast ezMulticast.addEzMulticastEventListener(this); //Activates EzMulticast -> Ready to send and receive data ezMulticast.setActive(true); //Sets all the swing components. frame.setTitle("Simple Multicast Chat"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel.setLayout(null); frame.getContentPane().add(panel); labelRcv.setText("Message Received: "); labelMsg.setText("Send a Message: "); buttonSend.setText("Send!"); labelRcv.setBounds(10,10,170,20); labelMsg.setBounds(10,35,170,20); textRcv.setBounds(125,10,330,20); textRcv.setEditable(false); textMsg.setBounds(125,35,250,20); buttonSend.setBounds(375,35,80,20); panel.add(labelRcv); panel.add(labelMsg); panel.add(textRcv); panel.add(textMsg); panel.add(buttonSend); frame.setSize(470,90); frame.setResizable(false); buttonSend.addActionListener(
new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { try{ //Sends a message to the group ezMulticast.send(textMsg.getText().getBytes()); }catch(EzMulticastException ex){ System.out.println(ex.getMessage()); } } }); }catch(EzMulticastException ex){ System.out.println(ex.getMessage()); } } /** Method called when EzMulticast receives a datagram */ public void dataIn(EzMulticastDataInEvent e){ String s = new String(e.data); textRcv.setText(s + " From : " + e.hostName); } }


Example 2: MulticastObject.java

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.addEzMulticastEventListener(this); ezMulticast.setActive(true); }catch(EzMulticastException ex){ System.out.println(ex.getMessage()); } } /** 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()); } } /** 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 rcv: " + ((Date)o).getTime()); //You can format the date the way you want here... } }catch(Exception ex){ System.out.println(ex.getMessage()); } } }