com.ezprotocols.ezmulticast
Class EzMulticast

java.lang.Object
  |
  +--com.ezprotocols.ezmulticast.EzMulticast
All Implemented Interfaces:
java.io.Serializable

public class EzMulticast
extends java.lang.Object
implements java.io.Serializable

EzMulticast 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.

Example:


import
com.ezprotocols.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()); } } }

See Also:
Serialized Form

Constructor Summary
EzMulticast()
           
 
Method Summary
 void addEzMulticastEventListener(EzMulticastEventListener client)
          Registers to receive event (DataIn).
 void fireDataIn(byte[] data, java.lang.String hostAddress, java.lang.String hostName, int hostPort)
          Fired when data is received.
 java.lang.String getAbout()
          Gets Information about EzMulticast.
 java.lang.String getGroupAddress()
          Gets the group address.
 int getGroupPort()
          Gets the group port number.
 int getInBufferSize()
          Gets the input buffer size.
 int getOutBufferSize()
          Gets the output buffer size.
 java.lang.String getSerialKey()
          Gets the Serial Key used to activate the full version.
 java.lang.String getVersion()
          Gets the version number of EzMulticast.
 boolean isActive()
          Returns true if EzMulticast can receive and send data.
 void removeEzMulticastEventListener(EzMulticastEventListener client)
          UnRegisters from receiving events.
 void send(byte[] message)
          Sends a datagram packet to the remote group.
 void setAbout(java.lang.String s)
           
 void setActive(boolean a)
          Enables or disables sending and receiving data.
 void setGroupAddress(java.lang.String s)
          Sets the address of the group.
 void setGroupPort(int p)
          Sets the group port.
 void setInBufferSize(int in)
          Sets the InBufferSize.
 void setOutBufferSize(int out)
          Sets the buffer size used for output.
 void setSerialKey(java.lang.String k)
          Sets the Serial Key to activate the full version.
 void setVersion(java.lang.String s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EzMulticast

public EzMulticast()
Method Detail

send

public void send(byte[] message)
          throws EzMulticastException
Sends a datagram packet to the remote group.

fireDataIn

public void fireDataIn(byte[] data,
                       java.lang.String hostAddress,
                       java.lang.String hostName,
                       int hostPort)
Fired when data is received.

addEzMulticastEventListener

public void addEzMulticastEventListener(EzMulticastEventListener client)
Registers to receive event (DataIn).

removeEzMulticastEventListener

public void removeEzMulticastEventListener(EzMulticastEventListener client)
UnRegisters from receiving events.

setGroupAddress

public void setGroupAddress(java.lang.String s)
Sets the address of the group.

setVersion

public void setVersion(java.lang.String s)

setGroupPort

public void setGroupPort(int p)
Sets the group port.

setInBufferSize

public void setInBufferSize(int in)
Sets the InBufferSize.
Increasing InBufferSize can increase the performance of network I/O for high-volume connection, while decreasing it can help reduce the backlog of incoming data.

setOutBufferSize

public void setOutBufferSize(int out)
Sets the buffer size used for output.

setActive

public void setActive(boolean a)
               throws EzMulticastException
Enables or disables sending and receiving data.

setAbout

public void setAbout(java.lang.String s)

setSerialKey

public void setSerialKey(java.lang.String k)
Sets the Serial Key to activate the full version.

getGroupAddress

public java.lang.String getGroupAddress()
Gets the group address.

getVersion

public java.lang.String getVersion()
Gets the version number of EzMulticast.

getGroupPort

public int getGroupPort()
Gets the group port number.

getInBufferSize

public int getInBufferSize()
Gets the input buffer size.

getOutBufferSize

public int getOutBufferSize()
Gets the output buffer size.

getAbout

public java.lang.String getAbout()
Gets Information about EzMulticast.

getSerialKey

public java.lang.String getSerialKey()
Gets the Serial Key used to activate the full version.

isActive

public boolean isActive()
Returns true if EzMulticast can receive and send data.


Copyright © EzProtocols.com All Rights Reserved.