context.arch.comm.protocol
Class MulticastUDPSocket

java.lang.Object
  extended bycontext.arch.comm.protocol.MulticastUDPSocket
All Implemented Interfaces:
java.lang.Cloneable, MulticastConstants, java.lang.Runnable
Direct Known Subclasses:
HTTPMulticastUDPSocket

public class MulticastUDPSocket
extends java.lang.Object
implements java.lang.Runnable, java.lang.Cloneable, MulticastConstants

This class implements a threaded server - client socket that accepts UDP multicast packets. It does nothing with the UDP packets themselves but can be subclassed to do real work. Whenever it receives data, it clones itself. The original class listens for more new incoming packets while the clone handles the received data. - Information about TTL (Time To Live) - You can specify the TTL for multicast packet. The TTL values are : 0 : transmitter 1 : local network 16 : site 32 : county 48 : country 64 : continent 128 : world

See Also:
Runnable, Cloneable

Field Summary
static boolean DEBUG
          Debug flag.
 
Fields inherited from interface context.arch.comm.protocol.MulticastConstants
DEFAULT_MULTICAST_ADDRESS, DEFAULT_MULTICAST_PORT, TTL_CONTINENT, TTL_COUNTRY, TTL_COUNTY, TTL_LOCAL_NETWORK, TTL_SITE, TTL_TRANSMITTER, TTL_WORLDWIDE
 
Constructor Summary
MulticastUDPSocket()
          Default constructor for MulticastUDPSocket, with the default port.
MulticastUDPSocket(int ttlValue)
           
 
Method Summary
 java.lang.String getMulticastGroup()
          Returns the group address
 int getMulticastPort()
          Returns the port number of the multicast group
static int getTTL()
          This method returns the Time To Live of the multicast socket
 void handleIncomingRequest(java.net.DatagramPacket data)
          This method handles data received on a given TCPServerSocket.
 void run()
          This method loops forever waiting for data on the socket.
 void sendPacket(java.lang.String msg)
           
 void setTTL(int valueTTL)
          This method allows to set the TTL
 void start()
          Starts a ServerSocket and a thread with this MulticastUDPSocket as the Runnable.
 void stopServer()
          Stops the original thread (just the original?) running and closes the socket.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static boolean DEBUG
Debug flag. Set to true to see debug messages.

Constructor Detail

MulticastUDPSocket

public MulticastUDPSocket()
Default constructor for MulticastUDPSocket, with the default port. The multicast address and port must be changed in the MulticastConstants class

See Also:
...

MulticastUDPSocket

public MulticastUDPSocket(int ttlValue)
Method Detail

start

public void start()
Starts a ServerSocket and a thread with this MulticastUDPSocket as the Runnable.


stopServer

public void stopServer()
Stops the original thread (just the original?) running and closes the socket.


run

public void run()
This method loops forever waiting for data on the socket. When data arrives, it clones a new instance of TCPServerSocket so the new thread can deal with the data, while the current instance looks for new data. The new thread deals with the data by calling handleIncomingRequest().

Specified by:
run in interface java.lang.Runnable
See Also:
#handleIncomingRequest(java.net.Socket)

handleIncomingRequest

public void handleIncomingRequest(java.net.DatagramPacket data)
This method handles data received on a given TCPServerSocket. Could be abstract since the method does nothing. A subclass is expected to override this method to handle the incoming data as necessary.

Parameters:
data - Socket the data is arriving on

sendPacket

public void sendPacket(java.lang.String msg)

getMulticastGroup

public java.lang.String getMulticastGroup()
Returns the group address

Returns:
Address of the multicast group

getMulticastPort

public int getMulticastPort()
Returns the port number of the multicast group

Returns:
Port number of the multicast group

setTTL

public void setTTL(int valueTTL)
This method allows to set the TTL

Parameters:
valueTTL - The TTL

getTTL

public static int getTTL()
This method returns the Time To Live of the multicast socket

Returns:
int The TTL