server
Class Client

java.lang.Object
  extended by java.lang.Thread
      extended by server.Client
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
Tester, ViewerClient

public abstract class Client
extends java.lang.Thread

A general client class for connecting to a server instance

Author:
Henry

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Client()
           
 
Method Summary
 void connect(java.lang.String address)
          connect to a server and open the default port
 boolean connect(java.lang.String address, int localPort)
          connect to a server and specifies a port to open up
 void disconnect()
          disconnect from the server
 java.lang.String getAddress()
          Get the address of the client
 boolean isConnected()
          Check if the clinet is connected
 void ping()
          send a packet receive a packet
 void run()
          be ready to receive packets
 void sendString(java.lang.String cmd)
          send a string to the server
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Client

public Client()
Method Detail

connect

public void connect(java.lang.String address)
             throws java.io.IOException
connect to a server and open the default port

Parameters:
address - the address of the server it should send data to
Throws:
java.io.IOException

connect

public boolean connect(java.lang.String address,
                       int localPort)
                throws java.io.IOException
connect to a server and specifies a port to open up

Parameters:
address - the address of the server it should send data to
localPort - the local port to open
Returns:
True if the connection was successful, False otherwise
Throws:
java.io.IOException

run

public void run()
be ready to receive packets

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

ping

public void ping()
send a packet receive a packet


disconnect

public void disconnect()
                throws java.io.IOException
disconnect from the server

Throws:
java.io.IOException

sendString

public void sendString(java.lang.String cmd)
                throws java.io.IOException
send a string to the server

Parameters:
cmd - the string to send to the server
Throws:
java.io.IOException

getAddress

public java.lang.String getAddress()
Get the address of the client

Returns:
the string form of the address of the client

isConnected

public boolean isConnected()
Check if the clinet is connected

Returns:
true if the client is connected