mhframework.net.server
Class MHServerModule
java.lang.Object
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.
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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DEFAULT_PORT
public static final int DEFAULT_PORT
- See Also:
- Constant Field Values
defaultColors
public final java.awt.Color[] defaultColors
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
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)