mhframework.net.server
Class MHServerModule

java.lang.Object
  extended by mhframework.net.server.MHServerModule

public class MHServerModule
extends java.lang.Object

The MHServerModule class provides a network interface for a multiplayer game server.

The class will automatically handle all of the message types defined in MHMessageType, but if your application has needs beyond those, then you must call setGameServer() and pass it an object that implements the MHGameServer interface. It is the game server that will receive any messages that this server module does not handle itself.

The code upon which this class is based was written by Greg Travis for IBM DeveloperWorks.


Field Summary
static int DEFAULT_PORT
           
 java.awt.Color[] defaultColors
           
 
Constructor Summary
MHServerModule()
          Creates a server module that listens for connections on the default port (MHServerModule.DEFAULT_PORT).
MHServerModule(int port)
          Creates a server module that listens for connections on the specified port.
 
Method Summary
 void broadcastClientList()
           
 void forwardMessage(MHClientInfo sender, MHNetworkMessage message)
           
 MHClientList getClientList()
           
 java.lang.String getIPAddress()
           
 int getMaxConnections()
           
 int getPort()
           
 boolean isListening()
           
static void main(java.lang.String[] args)
           
 void reset()
           
 void send(int recipientClientID, MHNetworkMessage message)
           
 void sendToAll(MHNetworkMessage message)
           
 void setClientColor(java.net.Socket socket, MHNetworkMessage message)
           
 void setClientName(java.net.Socket socket, MHNetworkMessage message)
           
 void setConnectionLimit(int connectionLimit)
           
 void setGameServer(MHGameServer gameServer)
           
 void shutdown()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

public static final int DEFAULT_PORT
See Also:
Constant Field Values

defaultColors

public final java.awt.Color[] defaultColors
Constructor Detail

MHServerModule

public MHServerModule()
               throws java.io.IOException
Creates a server module that listens for connections on the default port (MHServerModule.DEFAULT_PORT).

Throws:
java.io.IOException

MHServerModule

public MHServerModule(int port)
               throws java.io.IOException
Creates a server module that listens for connections on the specified port.

Throws:
java.io.IOException
Method Detail

reset

public void reset()

isListening

public boolean isListening()

broadcastClientList

public void broadcastClientList()

send

public void send(int recipientClientID,
                 MHNetworkMessage message)

sendToAll

public void sendToAll(MHNetworkMessage message)

getPort

public int getPort()

getIPAddress

public java.lang.String getIPAddress()

setGameServer

public void setGameServer(MHGameServer gameServer)

getClientList

public MHClientList getClientList()

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception

forwardMessage

public void forwardMessage(MHClientInfo sender,
                           MHNetworkMessage message)

setClientName

public void setClientName(java.net.Socket socket,
                          MHNetworkMessage message)

shutdown

public void shutdown()

setClientColor

public void setClientColor(java.net.Socket socket,
                           MHNetworkMessage message)

getMaxConnections

public int getMaxConnections()

setConnectionLimit

public void setConnectionLimit(int connectionLimit)