sg.edu.nus.peer.request
Class UDPSender

java.lang.Object
  extended by java.util.TimerTask
      extended by sg.edu.nus.peer.request.UDPSender
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
BootstrapPnPSender, ServerPnPSender

public abstract class UDPSender
extends java.util.TimerTask

The UDPSender is responsible for send UDP packets to remote users.

All concrete senders should extend UDPSender by implementing the method sendPacket().

Version:
1.0 2006-9-22
Author:
Xu Linhao
See Also:
BootstrapPnPSender, UDPReceiver

Constructor Summary
UDPSender(AbstractMainFrame gui, int port)
          Construct UDPSender by initializing DatagramSocket at the specified port, the server list and the stop flag as false.
 
Method Summary
 java.net.DatagramSocket getDatagramSocket()
          Returns the instance of the DatagramSocket.
 int getLocalPort()
          Returns the port used for running DatagramSocket.
 boolean isAlive()
          Returns true if the UDPSender is still alive.
 void run()
          Start the service of UDPSender.
 
Methods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UDPSender

public UDPSender(AbstractMainFrame gui,
                 int port)
          throws java.net.SocketException
Construct UDPSender by initializing DatagramSocket at the specified port, the server list and the stop flag as false.

Parameters:
gui - the main frame
port - the port that the DatagramSocket will be initialized
Throws:
java.net.SocketException
Method Detail

getDatagramSocket

public java.net.DatagramSocket getDatagramSocket()
Returns the instance of the DatagramSocket.

Returns:
the instance of the DatagramSocket

getLocalPort

public int getLocalPort()
Returns the port used for running DatagramSocket.

Returns:
the port used for running DatagramSocket

isAlive

public boolean isAlive()
Returns true if the UDPSender is still alive.

Returns:
true if alive; otherwise, return false

run

public void run()
Start the service of UDPSender.

Specified by:
run in interface java.lang.Runnable
Specified by:
run in class java.util.TimerTask