Cliser

cliser
Class UDPCommunicator

java.lang.Object
  |
  +--cliser.Communicator
        |
        +--cliser.UDPCommunicator
Direct Known Subclasses:
ClientUDPCommunicator, ServerUDPCommunicator

public abstract class UDPCommunicator
extends Communicator


Field Summary
static int PACKET_MAX
           
 
Constructor Summary
UDPCommunicator(java.lang.String remoteHost, int port)
          explicit constructor
UDPCommunicator(UDPCommunicator aCommunicator)
          pseudo copy constructor
 
Method Summary
protected  void finalize()
          destructor POST: mySocket is closed.
protected  java.net.DatagramPacket getLastPacket()
          myLastPacket accessor
 java.net.InetAddress getLastSender()
          accessor to retrieve last sender from last packet PRE: Someone has sent me a packet.
 int getLastSendersPort()
          accessor to retrieve port from last packet PRE: Someone has sent me a packet.
 java.lang.String getLocalHost()
          local host accessor
 int getLocalPort()
          local port accessor
 java.lang.String getRemoteHost()
          remote host accessor
 int getRemotePort()
          remote port accessor
protected  java.net.DatagramSocket getSocket()
          mySocket accessor
protected abstract  java.net.DatagramSocket initSocket()
          polymorphic socket initialization method
 java.lang.String receive()
          receive() primitive PRE: Someone is sending me a message.
 void send(java.lang.String message)
          send() primitive
protected  void setLastPacket(java.net.DatagramPacket aPacket)
          myLastPacket mutator
 void setTimeOut(int milliseconds)
          wrapper for DatagramSocket.setSoTimeout
 
Methods inherited from class cliser.Communicator
getPort, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PACKET_MAX

public static final int PACKET_MAX
Constructor Detail

UDPCommunicator

public UDPCommunicator(java.lang.String remoteHost,
                       int port)
explicit constructor

UDPCommunicator

public UDPCommunicator(UDPCommunicator aCommunicator)
pseudo copy constructor
Method Detail

initSocket

protected abstract java.net.DatagramSocket initSocket()
polymorphic socket initialization method
Returns:
a DatagramSocket initialized appropriately.

finalize

protected void finalize()
                 throws java.lang.Throwable
destructor POST: mySocket is closed.
Overrides:
finalize in class java.lang.Object

getLocalHost

public final java.lang.String getLocalHost()
local host accessor
Returns:
the host on which I am being used.
Overrides:
getLocalHost in class Communicator

getRemoteHost

public final java.lang.String getRemoteHost()
remote host accessor
Returns:
the remote host to which I am connected (or from which I last heard).
Overrides:
getRemoteHost in class Communicator

getRemotePort

public final int getRemotePort()
remote port accessor
Returns:
the remote port to which I am connected (or from which I last heard).
Overrides:
getRemotePort in class Communicator

getLocalPort

public final int getLocalPort()
local port accessor
Returns:
the (local) port I am using
Overrides:
getLocalPort in class Communicator

getLastSender

public final java.net.InetAddress getLastSender()
accessor to retrieve last sender from last packet PRE: Someone has sent me a packet.
Returns:
the sender of the last packet I received

getLastSendersPort

public final int getLastSendersPort()
accessor to retrieve port from last packet PRE: Someone has sent me a packet.
Returns:
the port of the last packet I received

setTimeOut

public final void setTimeOut(int milliseconds)
                      throws java.net.SocketException
wrapper for DatagramSocket.setSoTimeout
Throws:
java.net.SocketException - if nothing has been received in milliseconds time.

send

public void send(java.lang.String message)
send() primitive
Overrides:
send in class Communicator

receive

public java.lang.String receive()
receive() primitive PRE: Someone is sending me a message.
Returns:
the next message sent to me.
Overrides:
receive in class Communicator

getSocket

protected final java.net.DatagramSocket getSocket()
mySocket accessor
Returns:
mySocket

getLastPacket

protected final java.net.DatagramPacket getLastPacket()
myLastPacket accessor
Returns:
myLastPacket

setLastPacket

protected void setLastPacket(java.net.DatagramPacket aPacket)
myLastPacket mutator

Cliser

Cliser is open-source freeware distributed under the GNU Public License.