| 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectspellcast.server.ServerConnectionHandler
public class ServerConnectionHandler
This class handles all incoming and outgoing network traffic. Since network io can be time consuming a thread is used.
On each loop through run():
Checks for and accepts one new connection.
Each open connection is checked for a new message and only one message per connection is received.
All out going messages are sent on the caller's thread.
| Constructor Summary | |
|---|---|
ServerConnectionHandler(VersionDetails programVersionDetails,
                        java.net.InetAddress bindAddress,
                        int port)
 | 
|
| Method Summary | |
|---|---|
 void | 
connect(IPCHandle handle,
        Id client)
Connect the handle with the specified Id.  | 
 void | 
disconnect(IPCHandle handle)
Disconnect the client.  | 
 IPCRequest | 
receive()
Removes the first event from the incoming event queue and returns it.  | 
 void | 
run()
This thread will start running when start is called and 
 continue running until the stop method is called. | 
 void | 
send(Id client,
     GameEvent event)
Send an event to the specified client.  | 
 void | 
sendToAll(GameEvent e)
Send the event to all clients.  | 
 void | 
start()
Allocate resources, create and start the thread.  | 
 void | 
stop()
Sets the isRunning flag to false which lets run exit the 
 infite loop. | 
| Methods inherited from class java.lang.Object | 
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Constructor Detail | 
|---|
public ServerConnectionHandler(VersionDetails programVersionDetails,
                               java.net.InetAddress bindAddress,
                               int port)
| Method Detail | 
|---|
public IPCRequest receive()
wait
 until one is added when a client sends the server an event, at which point 
 the thread will be notified.
receive in interface IPC
public void send(Id client,
                 GameEvent event)
send in interface IPCpublic void sendToAll(GameEvent e)
send multiple times for all clients.
sendToAll in interface IPCpublic void run()
start is called and 
 continue running until the stop method is called.
 On each loop through run():
Checks for and accepts one new connection.
Each open connection is checked for a new message and only one message per connection is received.
run in interface java.lang.Runnable
public void connect(IPCHandle handle,
                    Id client)
connect in interface IPCpublic void disconnect(IPCHandle handle)
disconnect in interface IPC
public void start()
           throws ServerException
cleanup.
ServerException - thrown if the server list socket could not be allocated.public void stop()
run exit the 
 infite loop. This method will wait until the thread dies before 
 calling cleanup where resources are deallocated.
  | 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||