mhframework.net.client
Class MHClientModule

java.lang.Object
  extended by mhframework.net.client.MHClientModule
All Implemented Interfaces:
java.lang.Runnable

public class MHClientModule
extends java.lang.Object
implements java.lang.Runnable

This class can be instantiated by any client application that needs to communicate with a multiplayer server. It simply needs the IP address, and optionally the port number, of the server.


Field Summary
static int STATUS_CONNECTED
           
static int STATUS_DISCONNECTED
           
 
Constructor Summary
MHClientModule(java.lang.String hostIP)
          Connects to the server specified by hostIP using the default port (5000), and then begins a background thread to receive messages.
MHClientModule(java.lang.String hostIP, int port)
          Connects to the server specified by hostIP on the port specified by port, and then begins a background thread to receive messages.
 
Method Summary
 void disconnect()
           
 int getClientID()
           
 MHSerializableClientList getClientList()
          Returns a list of clients who are connected to the same server as this client module.
 int getMaxConnections()
           
 MHNetworkMessage getMessage()
          Retrieve the next message from the queue.
 java.lang.String getPlayerName()
           
 int getStatus()
           
 java.lang.String getStatusMessage()
           
 boolean isMessageWaiting()
          Return true if the queue of incoming messages is not empty; return false it if is.
 MHNetworkMessage peek()
          Peek at the next message in the queue without removing it.
 void registerPlayerColor(java.awt.Color color)
           
 void registerPlayerName(java.lang.String name)
           
 void run()
          Continuously receives server messages and adds them to this class' internal message queue.
 void sendChat(java.lang.String message)
           
 void sendMessage(MHNetworkMessage message)
          Sends a message to the server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATUS_CONNECTED

public static final int STATUS_CONNECTED
See Also:
Constant Field Values

STATUS_DISCONNECTED

public static final int STATUS_DISCONNECTED
See Also:
Constant Field Values
Constructor Detail

MHClientModule

public MHClientModule(java.lang.String hostIP)
Connects to the server specified by hostIP using the default port (5000), and then begins a background thread to receive messages.

Parameters:
hostIP - A string containing the IP address of the server

MHClientModule

public MHClientModule(java.lang.String hostIP,
                      int port)
Connects to the server specified by hostIP on the port specified by port, and then begins a background thread to receive messages.

Parameters:
hostIP - A string containing the IP address of the server.
port - An integer indicating the server's listening port.
Method Detail

getClientID

public int getClientID()

getMessage

public MHNetworkMessage getMessage()
Retrieve the next message from the queue.

Returns:
The next message from the queue.

peek

public MHNetworkMessage peek()
Peek at the next message in the queue without removing it.

Returns:
The next message from the queue.

isMessageWaiting

public boolean isMessageWaiting()
Return true if the queue of incoming messages is not empty; return false it if is.

Returns:
True if there is an incoming message waiting, false otherwise.

run

public void run()
Continuously receives server messages and adds them to this class' internal message queue. If the message is recognized as a standard game engine message, this class responds to it. Otherwise it is queued up for the game to retrieve and handle.

Specified by:
run in interface java.lang.Runnable

getStatus

public int getStatus()

getStatusMessage

public java.lang.String getStatusMessage()

getClientList

public MHSerializableClientList getClientList()
Returns a list of clients who are connected to the same server as this client module.

Returns:
A list of all clients connected to the same server.

sendMessage

public void sendMessage(MHNetworkMessage message)
Sends a message to the server.


disconnect

public void disconnect()

getMaxConnections

public int getMaxConnections()

sendChat

public void sendChat(java.lang.String message)

registerPlayerName

public void registerPlayerName(java.lang.String name)

registerPlayerColor

public void registerPlayerColor(java.awt.Color color)

getPlayerName

public java.lang.String getPlayerName()