|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
NetworkIO.ClientBase
public class ClientBase
ClientBase maintains a connection with a server of some kind. It will not allow for any connections to be made to it, nor is it able to connect to more than one server at a time.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
protected boolean |
connected
|
protected java.net.Socket |
connection
|
protected java.util.HashSet |
connectionListeners
|
protected java.io.ObjectInputStream |
input
|
protected NetworkLogger |
logger
|
protected java.util.HashSet |
networkListeners
|
protected java.io.ObjectOutputStream |
output
|
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
ClientBase(java.net.Socket socket)
Creates a new instance of ClientBase using a pre-defined Socket to create a connection. |
|
ClientBase(java.lang.String host,
int port)
Creates a new instance of ClientBase using a String host and int port to create a socket connection. |
Method Summary | |
---|---|
void |
addConnectionListener(ConnectionListener listener)
Adds a ConnectionListener to Client base in case of a lost connection. |
void |
addNetworkListener(NetworkListener listener)
Adds a NetworkListener to ClientBase so that any incomming connection will be sent to it. |
protected java.net.Socket |
connect(java.lang.String host,
int port)
Creates and returns a socket created from the recieved host and port. |
void |
disconnect()
Disconnects from the current connected server. |
java.net.Socket |
getSocket()
Returns the current Socket connection. |
protected void |
getStreams()
Registers the input and output streams to establish a communication connection. |
void |
run()
Starts the client's process of recieving Messages and telling NetworkListeners to process them. |
void |
send(Message message)
Sends the Message to the connected 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 |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected NetworkLogger logger
protected java.net.Socket connection
protected java.util.HashSet networkListeners
protected java.util.HashSet connectionListeners
protected java.io.ObjectInputStream input
protected java.io.ObjectOutputStream output
protected boolean connected
Constructor Detail |
---|
public ClientBase(java.lang.String host, int port) throws java.lang.Exception
host
- The host name of a computer running a valid server.port
- The port of the computer to connect to.
java.lang.Exception
- Any exception that occurs while creating a socket and registering a connection.public ClientBase(java.net.Socket socket) throws java.lang.Exception
socket
- The connected socket to another computer.
java.lang.Exception
- Any exception occuring while registering a connection.Method Detail |
---|
protected java.net.Socket connect(java.lang.String host, int port) throws java.lang.Exception
host
- The host name of the computer running a valid server.port
- The port of the computer to connect to.
java.lang.Exception
- Any exception that occured while trying to establish a connection to the serving
computer.protected void getStreams() throws java.lang.Exception
java.lang.Exception
- Any exception occured while registering input and output streams.public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void send(Message message) throws java.lang.Exception
message
- The Message to send.
java.lang.Exception
- Any exception that occurs while trying to send the message.public java.net.Socket getSocket()
public void disconnect()
public void addNetworkListener(NetworkListener listener)
listener
- The NetworkListener to add.public void addConnectionListener(ConnectionListener listener)
listener
- The ConnectionListener to add.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |