Cliser

cliser
Class TCPCommunicator

java.lang.Object
  |
  +--cliser.Communicator
        |
        +--cliser.TCPCommunicator
Direct Known Subclasses:
ClientTCPCommunicator, ServerTCPCommunicator

public abstract class TCPCommunicator
extends Communicator


Constructor Summary
TCPCommunicator()
          default constructor POST: my instance variables are initialized to default values: myRemoteHost == null && mySocket == null.
TCPCommunicator(java.net.Socket aSocket)
           
TCPCommunicator(java.lang.String remoteHost, int port)
          explicit constructor
 
Method Summary
protected  void finalize()
          destructor POST: mySocket has been closed
 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.Socket getSocket()
          mySocket accessor
protected  void initReaderAndWriter()
          initialize myReader and myWriter PRE: mySocket has been initialized POST: myReader is a wrapper for mySocket.getInputStream() && myWriter is a wrapper for mySocket.getOutputStream()
protected abstract  java.net.Socket initSocket()
          abstract socket initialization method (different in client and server Communicators)
 java.lang.String receive()
          receive() primitive PRE: Someone is sending a message to me.
 void send(java.lang.String message)
          send() primitive
protected  void setSocket(java.net.Socket aSocket)
          mySocket mutator (useable only by subclasses)
 
Methods inherited from class cliser.Communicator
getPort, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TCPCommunicator

public TCPCommunicator()
default constructor POST: my instance variables are initialized to default values: myRemoteHost == null && mySocket == null.

TCPCommunicator

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

TCPCommunicator

public TCPCommunicator(java.net.Socket aSocket)
Method Detail

initReaderAndWriter

protected void initReaderAndWriter()
initialize myReader and myWriter PRE: mySocket has been initialized POST: myReader is a wrapper for mySocket.getInputStream() && myWriter is a wrapper for mySocket.getOutputStream()

finalize

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

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 a message to me.
Returns:
the message someone sent to me.
Overrides:
receive in class Communicator

initSocket

protected abstract java.net.Socket initSocket()
abstract socket initialization method (different in client and server Communicators)

setSocket

protected void setSocket(java.net.Socket aSocket)
mySocket mutator (useable only by subclasses)
Parameters:
aSocket, - a Socket POST: mySocket == aSocket.

getSocket

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

getLocalPort

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

getLocalHost

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

getRemotePort

public final int getRemotePort()
remote port accessor
Returns:
the port on a remote host to which I am connected
Overrides:
getRemotePort in class Communicator

getRemoteHost

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

Cliser

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