net.directj.csf
Interface Client

All Superinterfaces:
java.lang.Runnable
All Known Implementing Classes:
ClientImpl

public interface Client
extends java.lang.Runnable

This a simple interface to implements a network client. It is a quite simple class, but it is powerfull enough to realize any networking application.

Version:
0.1.5
Author:
CARTAPANIS Alexandre <earendil@jprolog.net>

Method Summary
 void addClientListener(ClientListener _listener)
          Adds a client listener to this class.
 void doRequest(byte[] _data)
          Send an request to the server.
 void fireEvent(ClientEvent _evt)
          Send a client event to the listeners
 java.net.InetAddress getInetAddress()
          Returns the address of the server this client is bounded to.
 java.lang.String getInfo()
          Returns the client's informations (port, address, version...).
 int getPort()
          Returns the port on which this client is bounded to.
 java.lang.String getStatus()
          Returns the client's status (state, ...).
 boolean isRunning()
          Indicates if the client is running or not.
 void onRequest(byte[] _data)
          Called when the client receive a request from the server.
 void removeAllClientListener()
          Removes all the listeners associated with this class.
 void removeClientListener(ClientListener _listener)
          Removes a specified client listener from the list.
 void setInetAddress(java.net.InetAddress _address)
          Changes the server's address.
 void setPort(int _port)
          Changes the client's port.
 void setSocketFactory(javax.net.SocketFactory _factory)
          Sets the SocketFactory.
 void startClient()
          Starts the client.
 void stopClient()
          Stops the client.
 java.lang.String toString()
          Returns a string representation of this client.
 
Methods inherited from interface java.lang.Runnable
run
 

Method Detail

onRequest

public void onRequest(byte[] _data)
               throws java.lang.IllegalStateException,
                      InvalidRequestException
Called when the client receive a request from the server. In fact, this must fire a ClientEvent and use the client's fireEvent method.

Parameters:
_data - The data received from the server.
Throws:
java.lang.IllegalStateException - If the client is not running.
InvalidRequestException - If the request received from the server is not valid.
See Also:
fireEvent(ClientEvent)

doRequest

public void doRequest(byte[] _data)
               throws java.lang.IllegalStateException,
                      InvalidRequestException
Send an request to the server.

Parameters:
_data - The answer to send to the server.
Throws:
java.lang.IllegalStateException - If the client is not running.
InvalidRequestException - If the request received from the server is not valid.

startClient

public void startClient()
Starts the client.


stopClient

public void stopClient()
Stops the client.


isRunning

public boolean isRunning()
Indicates if the client is running or not.

Returns:
boolean - True if the client is running, false otherwise.

setSocketFactory

public void setSocketFactory(javax.net.SocketFactory _factory)
                      throws java.lang.IllegalStateException,
                             java.lang.IllegalArgumentException
Sets the SocketFactory. The factory is used to create the socket. Cannot be used if the client is running.

Parameters:
_factory - The socket factory.
Throws:
java.lang.IllegalStateException - If the client is running.
java.lang.IllegalArgumentException - If the SocketFactory is not valid or has not been initialized.

addClientListener

public void addClientListener(ClientListener _listener)
Adds a client listener to this class.

Parameters:
_listener - The Listener to add.

removeClientListener

public void removeClientListener(ClientListener _listener)
Removes a specified client listener from the list.

Parameters:
_listener - The Listener to remove.

removeAllClientListener

public void removeAllClientListener()
Removes all the listeners associated with this class.


fireEvent

public void fireEvent(ClientEvent _evt)
Send a client event to the listeners

Parameters:
_evt - The event to be fired.

getInfo

public java.lang.String getInfo()
Returns the client's informations (port, address, version...).

Returns:
String - The client's informations.

getStatus

public java.lang.String getStatus()
Returns the client's status (state, ...).

Returns:
String - The client's status.

getPort

public int getPort()
Returns the port on which this client is bounded to.

Returns:
int - The port number to which this client is bounded to.

toString

public java.lang.String toString()
Returns a string representation of this client.

Overrides:
toString in class java.lang.Object
Returns:
String - A string representation of this client.

setPort

public void setPort(int _port)
             throws java.lang.IllegalStateException,
                    java.lang.IllegalArgumentException
Changes the client's port. Cannot be used if the client is running. The port must be between 0 and 65535, inclusive.

Parameters:
_port - The new client's port.
Throws:
java.lang.IllegalStateException - If the client is running.
java.lang.IllegalArgumentException - If the port is not valid.

getInetAddress

public java.net.InetAddress getInetAddress()
Returns the address of the server this client is bounded to.

Returns:
InetAddress - A InetAddress representing the address of the server this client is bouded to.

setInetAddress

public void setInetAddress(java.net.InetAddress _address)
                    throws java.lang.IllegalStateException,
                           java.lang.IllegalArgumentException
Changes the server's address. Cannot be used if the client is running.

Parameters:
_address - The new server's address.
Throws:
java.lang.IllegalStateException - If the client is running.
java.lang.IllegalArgumentException - If the address is not valid.


Copyright 2002 CARTAPANIS Alexandre
This page was last updated on May 10 2003