vooga.network
Class VoogaServer

java.lang.Object
  extended by java.lang.Thread
      extended by vooga.network.VoogaServer
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
VoogaChatServer, VoogaGameServer, VoogaLobbyServer, VoogaUtilsServer

public abstract class VoogaServer
extends java.lang.Thread

VoogaServer maintains map of all open sockets and maintains set of connected users.

Author:
tgr3, tws10, sam1

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static java.lang.String SERVER
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
VoogaServer(int port)
          Creates a server that listens for client connections on the given port.
 
Method Summary
protected  java.util.Set<java.lang.String> getAllConnectedUsers()
           
 java.io.ObjectInputStream getInStream(java.lang.String userName)
          Gets the input stream that receives data from the named client.
 java.net.ServerSocket getMySocket()
          Allows subclasses to reference their socket.
 java.io.ObjectOutputStream getOutStream(java.lang.String userName)
          Gets the output stream that will send data to the named client.
protected abstract  void initialize()
          Allows subclasses to perform an additional initialization after the server has been constructed and started listening.
protected abstract  void intializeConnection(java.lang.String clientName, java.net.Socket clientSocket)
          Allows server subclasses to implement additional initialization for a user connection, such as starting a server thread to receive input from that client.
 boolean listeningToSocket(java.lang.String userName)
          Checks whether or not the server is currently listening to a connection from a client with the given userName.
 void removeConnection(java.lang.String userName)
           
 void run()
           
 
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

SERVER

public static final java.lang.String SERVER
See Also:
Constant Field Values
Constructor Detail

VoogaServer

public VoogaServer(int port)
            throws java.io.IOException
Creates a server that listens for client connections on the given port.

Parameters:
port -
Throws:
java.io.IOException
Method Detail

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

initialize

protected abstract void initialize()
Allows subclasses to perform an additional initialization after the server has been constructed and started listening.


intializeConnection

protected abstract void intializeConnection(java.lang.String clientName,
                                            java.net.Socket clientSocket)
Allows server subclasses to implement additional initialization for a user connection, such as starting a server thread to receive input from that client.


getMySocket

public java.net.ServerSocket getMySocket()
Allows subclasses to reference their socket.

Returns:
socket of server

getInStream

public java.io.ObjectInputStream getInStream(java.lang.String userName)
Gets the input stream that receives data from the named client.

Parameters:
userName -
Returns:

getOutStream

public java.io.ObjectOutputStream getOutStream(java.lang.String userName)
Gets the output stream that will send data to the named client.

Parameters:
userName -
Returns:

listeningToSocket

public boolean listeningToSocket(java.lang.String userName)
Checks whether or not the server is currently listening to a connection from a client with the given userName.

Parameters:
userName -
Returns:

getAllConnectedUsers

protected java.util.Set<java.lang.String> getAllConnectedUsers()
Returns:
set of all connected client users

removeConnection

public void removeConnection(java.lang.String userName)
Parameters:
userName - to be removed from a connection