org.openuat.util
Class UDPMulticastSocket

java.lang.Object
  extended by org.openuat.util.UDPMulticastSocket

public class UDPMulticastSocket
extends java.lang.Object

This class offers unicast and multicast UDP communication. It binds one MulticastSocket to each network interface address found in the system and sends multicast packets via all of them. Received packets can be either unicast or multicast, and a method to send only unicast packets is also offered.

Version:
1.0
Author:
Rene Mayrhofer

Field Summary
static java.lang.String[] Interface_Names_Blacklist
          A list of network interface names not to use for communication.
 
Constructor Summary
UDPMulticastSocket(int receivePort, int sendPort, java.lang.String multicastGroup)
          Creates an UDPMulticastSocket object.
 
Method Summary
 void addIncomingMessageListener(MessageListener l)
          Register a listener for receiving messages.
 void dispose()
          Leaves the multicast group on all sockets.
 boolean removeIncomingMessageListener(MessageListener l)
          De-register a listener for receiving messages.
 void sendMulticast(byte[] message)
          Sends a multicast message to the group.
 void sendTo(byte[] message, java.net.InetAddress target)
          Send a unicast message to a specific address.
 void startListening()
          Starts one thread for each interface to listen on, if not already started.
 void stopListening()
          Signals all listening threads to stop and waits for each of them.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Interface_Names_Blacklist

public static final java.lang.String[] Interface_Names_Blacklist
A list of network interface names not to use for communication. All other network interfaces not matching these names are used to multicast messages.

Constructor Detail

UDPMulticastSocket

public UDPMulticastSocket(int receivePort,
                          int sendPort,
                          java.lang.String multicastGroup)
                   throws java.io.IOException
Creates an UDPMulticastSocket object.

Parameters:
port - The UDP port to use for communication.
multicastGroup - The multicast group to use.
Throws:
java.io.IOException
Method Detail

sendMulticast

public void sendMulticast(byte[] message)
                   throws java.io.IOException
Sends a multicast message to the group. This will send at exactly one packet on each interface.

Parameters:
message - The message to send.
Throws:
java.io.IOException
See Also:
addressIsAlias

sendTo

public void sendTo(byte[] message,
                   java.net.InetAddress target)
            throws java.io.IOException
Send a unicast message to a specific address. This will use the system routing table to determine the appropriate interface to send the packet to.

Parameters:
message - The message to send.
target - The target address to send to.
Throws:
java.io.IOException

addIncomingMessageListener

public void addIncomingMessageListener(MessageListener l)
Register a listener for receiving messages.


removeIncomingMessageListener

public boolean removeIncomingMessageListener(MessageListener l)
De-register a listener for receiving messages.


dispose

public void dispose()
Leaves the multicast group on all sockets.


startListening

public void startListening()
Starts one thread for each interface to listen on, if not already started.

See Also:
#multicastSockets, #listenerThreads

stopListening

public void stopListening()
Signals all listening threads to stop and waits for each of them.

See Also:
shouldExit, #listenerThreads


2005-2006, Rene Mayrhofer.