net.sf.freecol.client.networking
Class Client

java.lang.Object
  extended by net.sf.freecol.client.networking.Client

public final class Client
extends java.lang.Object

The client that can connect to a server.


Constructor Summary
Client(java.lang.String host, int port, MessageHandler handler)
          Creates a new Client.
 
Method Summary
 org.w3c.dom.Element ask(org.w3c.dom.Element element)
          Sends the specified message to the server and returns the reply.
 void disconnect()
          Disconnects this client from the server.
 Connection getConnection()
          Gets the Connection this Client uses when communicating with the server.
 java.lang.String getHost()
           
 int getPort()
           
 void send(org.w3c.dom.Element element)
          Sends the specified message to the server.
 void sendAndWait(org.w3c.dom.Element element)
          Sends the specified message to the server and waits for the reply to be returned before returning from this method.
 void setMessageHandler(MessageHandler mh)
          Sets the MessageHandler for this Client.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Client

public Client(java.lang.String host,
              int port,
              MessageHandler handler)
       throws java.io.IOException
Creates a new Client.

Parameters:
host - The host to connect to.
port - The port to connect to.
handler - The MessageHandler to use.
Throws:
java.io.IOException - If an exception is thrown while creating a new Connection.
Method Detail

getHost

public java.lang.String getHost()

getPort

public int getPort()

send

public void send(org.w3c.dom.Element element)
Sends the specified message to the server.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information
See Also:
sendAndWait(Element), ask(Element)

sendAndWait

public void sendAndWait(org.w3c.dom.Element element)
Sends the specified message to the server and waits for the reply to be returned before returning from this method.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information
See Also:
send(Element), ask(Element)

ask

public org.w3c.dom.Element ask(org.w3c.dom.Element element)
Sends the specified message to the server and returns the reply.

Parameters:
element - The element (root element in a DOM-parsed XML tree) that holds all the information
Returns:
The answer from the server or null if either an error occured or the server did not send a reply.
See Also:
sendAndWait(org.w3c.dom.Element), send(org.w3c.dom.Element)

getConnection

public Connection getConnection()
Gets the Connection this Client uses when communicating with the server.

Returns:
The Connection.

disconnect

public void disconnect()
Disconnects this client from the server.


setMessageHandler

public void setMessageHandler(MessageHandler mh)
Sets the MessageHandler for this Client. The MessageHandler is the class responsible for receiving and handling the network messages.

Parameters:
mh - The new MessageHandler for this Client.