tipgame.net
Class Server

java.lang.Object
  extended by java.lang.Thread
      extended by tipgame.net.Server
All Implemented Interfaces:
java.lang.Runnable

public class Server
extends java.lang.Thread

This is used to receive and transmit data for consistency. The server is the authority of all information and all clients run in lock step with the server on a common clock. Upon a client connecting, the server sends:

  1. id of the client as an int
  2. keyboard array
  3. mouse array
  4. message array
      When the server starts running, at each frame advance it reads from each client:
      1. keyboard
      2. mouse
      3. message
      then it sends to each client:
      1. the timeInteverval as a double
      2. keyboard array
      3. mouse array
      4. message array
      The timeInterval is used to keep the clocks in sync. *

      Author:
      Jam Jenkins

      Nested Class Summary
      (package private)  class Server.Dispatcher
                communicates with the client to determine which game to join
       
      Nested classes/interfaces inherited from class java.lang.Thread
      java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
       
      Field Summary
      private  boolean connected
                true indicates still accepting new connections, false indicates accepting no more connections
      private  java.util.HashMap<java.lang.String,GameConnections> games
                map of currently running games to the GameConnections
      private  java.io.ObjectInputStream pipedIn
                the input stream used for applets
      private  java.io.ObjectOutputStream pipedOut
                the output stream used for applets
      static int PORT
                port on which to run the server
      private  java.net.ServerSocket serverSocket
                the socket listening for new connections
       
      Fields inherited from class java.lang.Thread
      MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
       
      Constructor Summary
      Server()
                 
      Server(java.lang.Object dummy)
                 
       
      Method Summary
       void connect()
                connects to a client and forwards the connections to the proper GameConnection
       void disconnect()
                stops the loop from accepting new connections
       java.io.ObjectInputStream getPipedInput()
                makes a piped input stream to use in applets
       java.io.ObjectOutputStream getPipedOutput()
                makes a piped output stream to use in applets
      static void main(java.lang.String[] argv)
                starts the server accepting new connections
       void run()
                starts the pipes for applets, or the server for applications
       void startPipes()
                starts pipe communications
       
      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

      PORT

      public static int PORT
      port on which to run the server


      games

      private java.util.HashMap<java.lang.String,GameConnections> games
      map of currently running games to the GameConnections


      connected

      private boolean connected
      true indicates still accepting new connections, false indicates accepting no more connections


      pipedOut

      private java.io.ObjectOutputStream pipedOut
      the output stream used for applets


      pipedIn

      private java.io.ObjectInputStream pipedIn
      the input stream used for applets


      serverSocket

      private java.net.ServerSocket serverSocket
      the socket listening for new connections

      Constructor Detail

      Server

      public Server(java.lang.Object dummy)

      Server

      public Server()
      Method Detail

      getPipedInput

      public java.io.ObjectInputStream getPipedInput()
      makes a piped input stream to use in applets

      Returns:
      the piped input stream connected to the server

      getPipedOutput

      public java.io.ObjectOutputStream getPipedOutput()
      makes a piped output stream to use in applets

      Returns:
      the piped output stream connected to the server

      startPipes

      public void startPipes()
      starts pipe communications


      connect

      public void connect()
      connects to a client and forwards the connections to the proper GameConnection

      Throws:
      java.lang.Exception - if an error occurs while establishing the initial connections

      disconnect

      public void disconnect()
      stops the loop from accepting new connections


      run

      public void run()
      starts the pipes for applets, or the server for applications

      Specified by:
      run in interface java.lang.Runnable
      Overrides:
      run in class java.lang.Thread
      See Also:
      Runnable.run()

      main

      public static void main(java.lang.String[] argv)
      starts the server accepting new connections

      Parameters:
      argv - not used