graphServer
Class UDPReceiver

java.lang.Object
  extended by graphServer.UDPReceiver

public class UDPReceiver
extends java.lang.Object

A UDPReceiver acts as a server where packets can be received and passed to objects which are interested in handling the packets the server receives.

Version:
Date: 18/07/2011
Author:
Matthew Smith
See Also:
UDPListener

Field Summary
static int maxDataPackets
           
static int theport
           
static int timeBetween
           
 
Constructor Summary
UDPReceiver()
          Construct the UDPReceiver sets up the port, UDP socket and threads for handling incoming packets.
UDPReceiver(int port)
          Construct the UDPReceiver sets up the port, UDP socket and threads for handling incoming packets.
 
Method Summary
 void addListener(UDPListener listener)
          Adds a UDP Listener to the list of listeners.
protected  void consumeData()
          Removes the first packet (earliest) from the list of received data and notifies any listeners of the packet.
 java.lang.String getDebugInfo()
          Returns a String with debug information about the UDP Receiver.
protected  void notifyReceiveMessage(java.net.DatagramPacket packet)
          Notifies all listeners on a new thread that a message has been received.
protected  void putData(java.net.DatagramPacket packet)
          Puts the most recently received packet at the end of the receivedData list.
 void startReceiving()
          Starts The thread listening to the UDP socket, and the thread which dispatches packets to any listeners.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theport

public static final int theport
See Also:
Constant Field Values

timeBetween

public static final int timeBetween
See Also:
Constant Field Values

maxDataPackets

public static final int maxDataPackets
See Also:
Constant Field Values
Constructor Detail

UDPReceiver

public UDPReceiver()
            throws java.net.SocketException
Construct the UDPReceiver sets up the port, UDP socket and threads for handling incoming packets.

Throws:
java.net.SocketException - If there was an error in creating the UDP socket.

UDPReceiver

public UDPReceiver(int port)
            throws java.net.SocketException
Construct the UDPReceiver sets up the port, UDP socket and threads for handling incoming packets.

Parameters:
port - The Port for the socket to use.
Throws:
java.net.SocketException - If there was an error in creating the UDP socket.
Method Detail

addListener

public void addListener(UDPListener listener)
Adds a UDP Listener to the list of listeners.

Parameters:
listener - The UDP Listener which will handle any incoming messages.
See Also:
UDPListener

notifyReceiveMessage

protected void notifyReceiveMessage(java.net.DatagramPacket packet)
Notifies all listeners on a new thread that a message has been received.

Parameters:
packet - the packet to notify listeners about.
See Also:
UDPListener

startReceiving

public void startReceiving()
Starts The thread listening to the UDP socket, and the thread which dispatches packets to any listeners.


putData

protected void putData(java.net.DatagramPacket packet)
Puts the most recently received packet at the end of the receivedData list.

Parameters:
packet - Most recently received packet from the UDP socket.
See Also:
Producer-Consumer

consumeData

protected void consumeData()
Removes the first packet (earliest) from the list of received data and notifies any listeners of the packet.

See Also:
Producer-Consumer

getDebugInfo

public java.lang.String getDebugInfo()
Returns a String with debug information about the UDP Receiver. Contains HTML attributes for being displayed in a browser.

Returns:
HTML String with debug information.