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 connection to a server.


Field Summary
private  Connection c
          The Connection this Client uses when communicating with the server.
private  java.lang.String host
           
private static java.util.logging.Logger logger
           
private  int port
           
 
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()
          Gets the host used by the connection.
 int getPort()
          Gets the port used by the connection.
 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

c

private final Connection c
The Connection this Client uses when communicating with the server.


host

private java.lang.String host

port

private int port
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()
Gets the host used by the connection. Used in reconnect.

Returns:
The host.

getPort

public int getPort()
Gets the port used by the connection. Used in reconnect.

Returns:
The port.

getConnection

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

Returns:
The Connection.

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.

disconnect

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


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)