fate.network
Class ServerConnection


java.lang.Object

  |

  +--java.lang.Thread

        |

        +--fate.network.ServerConnection


public class ServerConnection
extends java.lang.Thread

Handles all networking on the server end.

Sets up a server socket to listen on a port and spawns ServerThread objects to handle messages.


Field Summary
static int FATE_PORT
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ServerConnection(int port, MapPlayerInfo mapPlayerInfo)
          Creates new ServerConnection
 
Method Summary
 void addServerThread(int id, ServerThread thread)
          Adds a ServerThread to the map
 boolean initialize()
          Initializes the server connection
 boolean messagesAvailable()
          Returns true if there are messages in the message buffer
 java.lang.Object nextMessage()
          Returns the next message in the buffer, or NULL is there are none.
 void receiveMessage(java.lang.Object msg)
          Called by the communications thread to receive a message
 void removeServerThread(int id)
          Removes a ServerThread from the map
 void run()
          Start processing of incoming connections
 boolean sendMessage(int idClient, GameMessage msg)
          Sends a message to a client.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, 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

FATE_PORT


public static final int FATE_PORT
Constructor Detail

ServerConnection


public ServerConnection(int port,
                        MapPlayerInfo mapPlayerInfo)
Creates new ServerConnection
Method Detail

initialize


public boolean initialize()
Initializes the server connection

run


public void run()
Start processing of incoming connections
Overrides:
run in class java.lang.Thread

addServerThread


public void addServerThread(int id,
                            ServerThread thread)
Adds a ServerThread to the map

removeServerThread


public void removeServerThread(int id)
Removes a ServerThread from the map

sendMessage


public boolean sendMessage(int idClient,
                           GameMessage msg)
                    throws java.io.IOException
Sends a message to a client. To look at: could this possibly hold up the server? Maybe this should spawn a thread to send the message..

receiveMessage


public void receiveMessage(java.lang.Object msg)
                    throws java.io.IOException
Called by the communications thread to receive a message

messagesAvailable


public boolean messagesAvailable()
Returns true if there are messages in the message buffer

nextMessage


public java.lang.Object nextMessage()
Returns the next message in the buffer, or NULL is there are none. Should check with messagesAvailable first to see if there are any