public final class Client
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private Connection |
c
The
Connection this Client uses when
communicating with the server. |
private java.lang.String |
host
The host to connect to.
|
private static java.util.logging.Logger |
logger |
private int |
port
The port to connect to.
|
Constructor and Description |
---|
Client(java.lang.String host,
int port,
MessageHandler handler,
java.lang.String name)
Creates a new
Client . |
Modifier and Type | Method and Description |
---|---|
org.w3c.dom.Element |
ask(DOMMessage message)
Sends the specified message to the server and returns the reply.
|
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.
|
org.w3c.dom.Element |
handleReply(org.w3c.dom.Element reply)
Handle a reply element using the client input handler.
|
void |
send(DOMMessage message)
Sends the specified message to the server.
|
void |
send(org.w3c.dom.Element element)
Sends the specified message to the server.
|
void |
sendAndWait(DOMMessage message)
Sends the specified message to the server and waits for the reply
to be returned before returning from this method.
|
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 . |
private static final java.util.logging.Logger logger
private final Connection c
Connection
this Client
uses when
communicating with the server.private final java.lang.String host
private final int port
public Client(java.lang.String host, int port, MessageHandler handler, java.lang.String name) throws java.io.IOException
Client
.host
- The host to connect to.port
- The port to connect to.handler
- The MessageHandler to use.
name
- The name for the connection.java.io.IOException
- If an exception is thrown while creating
a new Connection
.public java.lang.String getHost()
public int getPort()
public Connection getConnection()
Connection
this Client
uses
when communicating with the server.Connection
.public void setMessageHandler(MessageHandler mh)
MessageHandler
for this Client
.
The MessageHandler
is the class responsible for receiving
and handling the network messages.mh
- The new MessageHandler
for this client.public void disconnect()
public void send(DOMMessage message) throws java.io.IOException
message
- The DOMMessage
to send.java.io.IOException
sendAndWait(Element)
,
ask(Element)
public void send(org.w3c.dom.Element element) throws java.io.IOException
element
- The element (root element in a DOM-parsed XML tree) that
holds all the informationjava.io.IOException
sendAndWait(Element)
,
ask(Element)
public void sendAndWait(DOMMessage message) throws java.io.IOException
message
- The DOMMessage
to send.java.io.IOException
send(Element)
,
ask(Element)
public void sendAndWait(org.w3c.dom.Element element) throws java.io.IOException
element
- The element (root element in a DOM-parsed XML tree) that
holds all the informationjava.io.IOException
send(Element)
,
ask(Element)
public org.w3c.dom.Element ask(DOMMessage message) throws java.io.IOException
message
- The DOMMessage
to send.null
if either
an error occured or the server did not send a reply.java.io.IOException
sendAndWait(net.sf.freecol.common.networking.DOMMessage)
,
send(net.sf.freecol.common.networking.DOMMessage)
public org.w3c.dom.Element ask(org.w3c.dom.Element element) throws java.io.IOException
element
- The element (root element in a DOM-parsed XML tree)
that holds all the informationnull
if either
an error occured or the server did not send a reply.java.io.IOException
sendAndWait(net.sf.freecol.common.networking.DOMMessage)
,
send(net.sf.freecol.common.networking.DOMMessage)
public org.w3c.dom.Element handleReply(org.w3c.dom.Element reply)
reply
- The reply Element
to handle.Element
.