feud.clientserver
Class SimpleClient

java.lang.Object
  extended byfeud.clientserver.SimpleClient

public class SimpleClient
extends java.lang.Object

This the client's counterpart to the SimpleServer. If connects to a SimpleServer and exchanges DataContainers with it.


Field Summary
static int INTERVAL
          This is the time in ms that the client waits between two transfers.
 
Constructor Summary
SimpleClient(ServerEntry se, boolean zip, DataContainer data)
          Creates a new SimpleClient.
SimpleClient(java.lang.String server, int port, boolean zip, DataContainer data)
          Creates a new SimpleClient.
 
Method Summary
 void addListener(DataTransferListener sl)
          Adds a DataTransferListener to the client.
 void addPreProcessor(ClientPreProcessor cpp)
          Adds a ClientPreProcessor to the client.
 void connect()
          Tries to connect to the configured server.
 void disconnect()
          Disconnects from a server.
 int getClientID()
          Returns this client's id.
 boolean isConnected()
          Is this client connected to a server?
 void setContainers(DataContainer[] c)
          Sets the data to be transfered to the server in the next transfer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTERVAL

public static final int INTERVAL
This is the time in ms that the client waits between two transfers.

See Also:
Constant Field Values
Constructor Detail

SimpleClient

public SimpleClient(java.lang.String server,
                    int port,
                    boolean zip,
                    DataContainer data)
Creates a new SimpleClient. The client won't connect to the server unless the connect()-method has been called.

Parameters:
server - the address of the server. This can be IPv4, IPv6 or a name.
port - the port on which the server is listening for clients to connect
zip - if true, all transfers (except for the login itself) will be zipped. This consumes more cpu power but reduces bandwidth usage.
data - an initial DataContainer. This container will be passed to the registered ClientLoginListeners (if any) by the server. The SimpleServer itself won't process it.

SimpleClient

public SimpleClient(ServerEntry se,
                    boolean zip,
                    DataContainer data)
Creates a new SimpleClient. The client won't connect to the server unless the connect()-method has been called.

Parameters:
se - the ServerEntry (usually taken from the ServerBrowser) that holds the server's data.
zip - if true, all transfers (except for the login itself) will be zipped. This consumes more cpu power but reduces bandwidth usage.
data - an initial DataContainer. This container will be passed to the registered ClientLoginListeners (if any) by the server. The SimpleServer itself won't process it.
Method Detail

connect

public void connect()
             throws java.lang.Exception
Tries to connect to the configured server. If that fails, an Exception will be thrown.

Throws:
java.lang.Exception - failed?

disconnect

public void disconnect()
Disconnects from a server. If there is no connection established, nothing will be done.


addListener

public void addListener(DataTransferListener sl)
Adds a DataTransferListener to the client. This listener will be called when the client receives data from the server.

Parameters:
sl - the listener

addPreProcessor

public void addPreProcessor(ClientPreProcessor cpp)
Adds a ClientPreProcessor to the client. A ClientPreProcessor will be called before sending to the server, before receiving from the server and after receiving from the server to allow its implementing class to do whats needed in these stages. For example, "before sending" should prepare the data to be send to the server and inject it into the SimpleClient.

Parameters:
cpp - ClientPreProcessor

setContainers

public void setContainers(DataContainer[] c)
Sets the data to be transfered to the server in the next transfer. This is usually called from inside an implementation of a ClientPreProcessor's beforeSending()-method.

Parameters:
c - an array of DataContainers

getClientID

public int getClientID()
Returns this client's id. Once connected, this is a positive integer that is unique on the server.

Returns:
int the id

isConnected

public boolean isConnected()
Is this client connected to a server?

Returns:
boolean is it?