network
Class AbCommsTCP

java.lang.Object
  extended by network.AbCommsTCP
All Implemented Interfaces:
java.io.Serializable, java.lang.Runnable
Direct Known Subclasses:
ServerComms, SocketComms

public abstract class AbCommsTCP
extends java.lang.Object
implements java.io.Serializable, java.lang.Runnable

Created on November 8, 2006, 4:31 PM
Abstract comms used as the parent for SendComms and RecieveComms.

Uses datagrams to handle the communications.
Sending or waiting for acks is handled by the classes that implement AbCommsTCP.
Each child implements and uses the socket, packet, remoteHost, and connectedAddress variables differently.
Created to help simplify and organize communications.
t.5 Changed from using datagrams to using tcp sockets instead.

Version:
t.5
Author:
Eric Angeli
See Also:
Serialized Form

Constructor Summary
AbCommsTCP()
          Creates a new instance of AbCommsTCP
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Adds the property change listener.
 byte[] getBuffer()
          The buffer of data to be sent.
 java.net.InetAddress getConnectedAddress()
          Get the address the socket is connected to.
 int getPort()
          Gets the port number the socket is bound.
 java.beans.PropertyChangeSupport getPropertySupport()
          Gets the property change support.
 java.lang.String getRemoteHost()
          Gets the remote host.
 java.lang.Thread getRunner()
          Gets the thread that is running.
 java.net.Socket getSocket()
          Gets the socket used for communications.
 boolean isAckRequired()
          Whether an ack is required or not.
Not used when using tcp sockets.
 boolean isAlreadyConnected()
          Whether the socket is already connected or not.
 boolean isPauseComms()
          The pause state of communications.
 boolean isRunning()
          Whether the thread should be running or not.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Removes the property change listener.
abstract  void run()
          Abstract run.
Used in subclasses to handle communications.
 void setAckRequired(boolean ackRequired)
          Set whether an ack is required or not.
 void setAlreadyConnected(boolean alreadyConnected)
          Set the connection status of the socket.
 void setBuffer(byte[] buffer)
          Sets the data buffer that is to be sent.
 void setConnectedAddress(java.net.InetAddress connectedAddress)
          Sets the connected address.
 void setPauseComms(boolean pauseComms)
          Sets the pause state of communications.
 void setPort(int port)
          Set the port number to use.
 void setRemoteHost(java.lang.String remoteHost)
          Sets the remote host connected to.
 void setRunner(java.lang.Thread runner)
          Sets the running thread.
 void setRunning(boolean running)
          Set the thread's current running state.
 void setSocket(java.net.Socket socket)
          Sets the socket to use for communications.
 void startComms()
          Starts the communications.
 void stopComms()
          Stops the communications.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbCommsTCP

public AbCommsTCP()
Creates a new instance of AbCommsTCP

Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds the property change listener.

Parameters:
listener - The new listener.

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes the property change listener.

Parameters:
listener - The listener to remove.

getPropertySupport

public java.beans.PropertyChangeSupport getPropertySupport()
Gets the property change support.

Returns:
The property change support.

getRunner

public java.lang.Thread getRunner()
Gets the thread that is running.

Returns:
The thread that is running.

setRunner

public void setRunner(java.lang.Thread runner)
Sets the running thread.

Parameters:
runner - The new thread to run.

isRunning

public boolean isRunning()
Whether the thread should be running or not.

Returns:
True if running, otherwise false.

setRunning

public void setRunning(boolean running)
Set the thread's current running state.

Parameters:
running - True if running, otherwise false.

isPauseComms

public boolean isPauseComms()
The pause state of communications.

Returns:
True if paused, otherwise false.

setPauseComms

public void setPauseComms(boolean pauseComms)
Sets the pause state of communications.

Parameters:
pauseComms - The new pause state.

getRemoteHost

public java.lang.String getRemoteHost()
Gets the remote host.

Returns:
The address of the remote host.

setRemoteHost

public void setRemoteHost(java.lang.String remoteHost)
Sets the remote host connected to.

Parameters:
remoteHost - The new remote host.

getSocket

public java.net.Socket getSocket()
Gets the socket used for communications.

Returns:
The connected socket.

setSocket

public void setSocket(java.net.Socket socket)
Sets the socket to use for communications.

Parameters:
socket - The new socket to use.

isAlreadyConnected

public boolean isAlreadyConnected()
Whether the socket is already connected or not.

Returns:
True if connected, otherwise false.

setAlreadyConnected

public void setAlreadyConnected(boolean alreadyConnected)
Set the connection status of the socket.

Parameters:
alreadyConnected - The new connection status of the socket.

getConnectedAddress

public java.net.InetAddress getConnectedAddress()
Get the address the socket is connected to.

Returns:
The address connected.

setConnectedAddress

public void setConnectedAddress(java.net.InetAddress connectedAddress)
Sets the connected address.

Parameters:
connectedAddress - The new address connected.

getPort

public int getPort()
Gets the port number the socket is bound.

Returns:
The port number

setPort

public void setPort(int port)
Set the port number to use.

Parameters:
port - The new port number.

getBuffer

public byte[] getBuffer()
The buffer of data to be sent.

Returns:
The string to be sent as a buffer array.

setBuffer

public void setBuffer(byte[] buffer)
Sets the data buffer that is to be sent.

Parameters:
buffer - The string to be sent as a buffer array.

isAckRequired

public boolean isAckRequired()
Whether an ack is required or not.
Not used when using tcp sockets.

Returns:
True if need an ack, otherwise false.

setAckRequired

public void setAckRequired(boolean ackRequired)
Set whether an ack is required or not.

Parameters:
ackRequired - True if require an ack, otherwise false.

startComms

public void startComms()
Starts the communications.


stopComms

public void stopComms()
Stops the communications.


run

public abstract void run()
Abstract run.
Used in subclasses to handle communications.

Specified by:
run in interface java.lang.Runnable