uk.ac.ic.doc.automed.p2p.communication
Class UDPClient

java.lang.Object
  extended by uk.ac.ic.doc.automed.p2p.communication.AbstractClient
      extended by uk.ac.ic.doc.automed.p2p.communication.UDPClient
All Implemented Interfaces:
Threadable

public class UDPClient
extends AbstractClient


Field Summary
 
Fields inherited from class uk.ac.ic.doc.automed.p2p.communication.AbstractClient
ackExpected, dataToSend, handler, isReady, serverHostName, serverPort
 
Constructor Summary
UDPClient(RequestListener handler)
           
UDPClient(java.lang.String serverHostName, int serverPort, RequestListener handler)
          Creates a new instance of UDPClient
UDPClient(java.lang.String serverHostName, int serverPort, RequestListener handler, byte[] dataToSend)
          Creates a new instance of UDPClient
 
Method Summary
 byte[] getReceivedData()
          Get the data received from server
 void handleAction()
          Handle thread's interrupted action
static java.net.DatagramPacket receiveDatagram(java.net.DatagramSocket socket)
          Receive response packets in a separate thread
 void runAction()
          Implement UDP communication process
static void sendDatagram(java.net.DatagramSocket dsock, byte[] dataToSend, java.net.InetAddress remoteAddress, int remotePort)
          An utility method for sending a datagram given a socket.
 
Methods inherited from class uk.ac.ic.doc.automed.p2p.communication.AbstractClient
getHandlerObject, getReadyState, setDataToSend, setReadyState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UDPClient

public UDPClient(java.lang.String serverHostName,
                 int serverPort,
                 RequestListener handler,
                 byte[] dataToSend)
Creates a new instance of UDPClient

Parameters:
serverHostName - host name of the UDP server
serverPort - UDP port on server
handler - an RequestListener object for processing messages
dataToSend - in array of bytes

UDPClient

public UDPClient(RequestListener handler)

UDPClient

public UDPClient(java.lang.String serverHostName,
                 int serverPort,
                 RequestListener handler)
Creates a new instance of UDPClient

Parameters:
serverHostName - host name of the UDP server
serverPort - UDP port on server
Method Detail

runAction

public void runAction()
               throws AutoMedException
Implement UDP communication process

Specified by:
runAction in interface Threadable
Specified by:
runAction in class AbstractClient
Throws:
AutoMedException

receiveDatagram

public static java.net.DatagramPacket receiveDatagram(java.net.DatagramSocket socket)
                                               throws CommunicationException
Receive response packets in a separate thread

Throws:
CommunicationException

handleAction

public void handleAction()
Handle thread's interrupted action

Specified by:
handleAction in interface Threadable
Specified by:
handleAction in class AbstractClient

getReceivedData

public byte[] getReceivedData()
Get the data received from server

Returns:
byte[] an array of bytes representing the received data

sendDatagram

public static void sendDatagram(java.net.DatagramSocket dsock,
                                byte[] dataToSend,
                                java.net.InetAddress remoteAddress,
                                int remotePort)
                         throws CommunicationException
An utility method for sending a datagram given a socket. This method performs
fragmentation based on Constants.PACKET_SIZE as needed.

Throws:
CommunicationException