|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--com.ezprotocols.ezmulticast.EzMulticast
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());
}
}
}
| 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 |
public EzMulticast()
| Method Detail |
public void send(byte[] message)
throws EzMulticastException
public void fireDataIn(byte[] data,
java.lang.String hostAddress,
java.lang.String hostName,
int hostPort)
public void addEzMulticastEventListener(EzMulticastEventListener client)
public void removeEzMulticastEventListener(EzMulticastEventListener client)
public void setGroupAddress(java.lang.String s)
public void setVersion(java.lang.String s)
public void setGroupPort(int p)
public void setInBufferSize(int in)
public void setOutBufferSize(int out)
public void setActive(boolean a)
throws EzMulticastException
public void setAbout(java.lang.String s)
public void setSerialKey(java.lang.String k)
public java.lang.String getGroupAddress()
public java.lang.String getVersion()
public int getGroupPort()
public int getInBufferSize()
public int getOutBufferSize()
public java.lang.String getAbout()
public java.lang.String getSerialKey()
public boolean isActive()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||