NetworkIO
Class ServerBase

java.lang.Object
  extended by java.lang.Thread
      extended by NetworkIO.ServerBase
All Implemented Interfaces:
java.lang.Runnable

public class ServerBase
extends java.lang.Thread

A ServerBase will recieved, and can make, connections to other servers, or clients that use this NetworkIO package.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  java.util.HashMap connections
           
protected  NetworkLogger logger
           
protected  int port
           
protected  java.net.ServerSocket serverSocket
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ServerBase(int port)
          Creates a new instance of ServerBase
 
Method Summary
 void addConnection(java.lang.String host, int port)
          Adds a connection.
 void addConnectionListener(ConnectionListener listener)
          Adds a ConnectionListener to listen to any new connections or lost connections.
 void addNetworkListener(NetworkListener listener)
          Adds a NetworkListener to process any incomming Messages.
 ClientBase getClientBase(java.net.Socket socket)
          Returns the ClientBase associated with the Socket connection.
 void run()
          Recieves and processes all incoming connections.
 void send(Message message, java.net.Socket socket)
          Sends a message to a specific connection.
 void sendToAll(Message message)
          Sends a Message to all connected clients.
 
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

logger

protected NetworkLogger logger

serverSocket

protected java.net.ServerSocket serverSocket

connections

protected java.util.HashMap connections

port

protected int port
Constructor Detail

ServerBase

public ServerBase(int port)
Creates a new instance of ServerBase

Parameters:
port - The port on which to host this server.
Method Detail

run

public void run()
Recieves and processes all incoming connections.

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

addConnection

public void addConnection(java.lang.String host,
                          int port)
Adds a connection.

Parameters:
host - The host computer running another server.
port - The port of the computer on which to connect to.

send

public void send(Message message,
                 java.net.Socket socket)
          throws java.lang.Exception
Sends a message to a specific connection.

Parameters:
message - The Message to send.
socket - The Socket connection to send the Message to.
Throws:
java.lang.Exception - Any exception that occurs while sending the message.

getClientBase

public ClientBase getClientBase(java.net.Socket socket)
Returns the ClientBase associated with the Socket connection.

Parameters:
socket - The Socket associated with the ClientBase.
Returns:
The ClientBase

sendToAll

public void sendToAll(Message message)
               throws java.lang.Exception
Sends a Message to all connected clients.

Parameters:
message - The Message to send.
Throws:
java.lang.Exception - Any exception that occurs while trying to send the Message.

addNetworkListener

public void addNetworkListener(NetworkListener listener)
Adds a NetworkListener to process any incomming Messages.

Parameters:
listener - The NetworkListener to listen to all incomming Messages.

addConnectionListener

public void addConnectionListener(ConnectionListener listener)
Adds a ConnectionListener to listen to any new connections or lost connections.

Parameters:
listener - The ConnectionListener to listen to any new connections or lost connections.