|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectglassfrog.server.Server
public class Server
The Server class is a persistant java server that has a ServerSocket
serving on port 9000. This ServerSocket handles incoming connections and
sends back information depending on the request made. The Server is capable
of creating a Room
, querying information about a Room or general
status
Each connection to the server is forked into a separate thread to allow
multiple conncurent connections to the Server. Each thread only stays alive
for the duration of the request connection and then is terminated.
Nested Class Summary | |
---|---|
class |
Server.ServerConnectionHandler
A class used to handle incoming connections to the server. |
Field Summary | |
---|---|
private static boolean |
alive
|
private static int |
CONNECTION_MAX
|
private static java.lang.String |
DUPLICATE_POLICY
|
private static java.util.ArrayList<java.lang.String> |
errorList
|
private java.io.FileWriter |
errorLog
|
private java.io.BufferedWriter |
errorLogWriter
|
private static java.util.ArrayList<java.lang.String> |
finishedList
|
private static java.util.ArrayList<java.lang.String> |
keyList
|
private static java.util.ArrayList<java.lang.Thread> |
liveThreads
|
private static int |
PORT
|
private static java.util.concurrent.CopyOnWriteArrayList<java.lang.Integer> |
portList
|
private static java.util.ArrayList<Room> |
rooms
|
private java.io.FileWriter |
serverLog
|
private java.io.BufferedWriter |
serverLogWriter
|
private static java.net.ServerSocket |
ss
|
private static int |
TIMEOUT
|
Constructor Summary | |
---|---|
Server(int timeout,
int port)
The constructor for the server starts up a server on port 9000 and opens a ServerSocket to handle server requests |
Method Summary | |
---|---|
private void |
houseKeeping()
Do some housekeeping whenever a new connection is started or every 30 seconds on the socket timeout |
private void |
initLogging()
Initialize the logs for the game. |
private static void |
loadSettings()
|
void |
logError(java.lang.Exception ex)
Utility for logging an error message to the errorLogger |
void |
logError(java.lang.Exception ex,
java.lang.String message)
Specify and extra message to the error logger |
private void |
logInfo(java.lang.String info)
Log a info to the serverLogger |
private void |
logWarning(java.lang.String warningMessage)
Utility for logging a warning message to the errorLogger |
static void |
main(java.lang.String[] args)
Start the server from the command line. |
void |
run()
The run method for the server. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static java.util.ArrayList<Room> rooms
private static java.util.concurrent.CopyOnWriteArrayList<java.lang.Integer> portList
private static java.util.ArrayList<java.lang.String> keyList
private static java.util.ArrayList<java.lang.Thread> liveThreads
private static java.util.ArrayList<java.lang.String> finishedList
private static java.util.ArrayList<java.lang.String> errorList
private static java.net.ServerSocket ss
private java.io.FileWriter errorLog
private java.io.FileWriter serverLog
private java.io.BufferedWriter errorLogWriter
private java.io.BufferedWriter serverLogWriter
private static boolean alive
private static int PORT
private static int TIMEOUT
private static java.lang.String DUPLICATE_POLICY
private static final int CONNECTION_MAX
Constructor Detail |
---|
public Server(int timeout, int port) throws java.net.BindException, java.io.IOException
timeout
- A timeout used for server connectionsport
- a port to start the server on
java.net.BindException
java.io.IOException
Method Detail |
---|
private void initLogging()
public void logError(java.lang.Exception ex)
ex
- public void logError(java.lang.Exception ex, java.lang.String message)
ex
- message
- private void logWarning(java.lang.String warningMessage)
warningMessage
- A message to log to the error logprivate void logInfo(java.lang.String info)
info
- the message to log to the room logpublic void run()
run
in interface java.lang.Runnable
private void houseKeeping()
public static void main(java.lang.String[] args)
args
- Command line argsprivate static void loadSettings() throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXParseException, org.xml.sax.SAXException, java.io.IOException, java.lang.InterruptedException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXParseException
org.xml.sax.SAXException
java.io.IOException
java.lang.InterruptedException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |