|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.directj.csf.impl.ClientImpl
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.
Nested Class Summary | |
private class |
ClientImpl.ShutdownHook
This class is used to stop the client at the end of the JVM. |
Field Summary | |
private java.net.InetAddress |
address
The server's address. |
private java.io.BufferedReader |
in
The input reader. |
private java.util.Vector |
listeners
The list of listeners. |
private java.io.PrintWriter |
out
The output writer. |
private int |
port
The server's port. |
private java.lang.Thread |
runner
The handler thread. |
private boolean |
running
Indicates if the handler is running or not. |
private java.net.Socket |
sock
The socket. |
private javax.net.SocketFactory |
socketFactory
The factory that will be used to create the socket. |
Constructor Summary | |
ClientImpl(int _port,
java.net.InetAddress _address)
Creates a new client implementation. |
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 |
run()
Runs the client. |
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 class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private java.io.BufferedReader in
private java.io.PrintWriter out
private volatile boolean running
private java.lang.Thread runner
private int port
private java.net.InetAddress address
private java.net.Socket sock
private java.util.Vector listeners
private javax.net.SocketFactory socketFactory
Constructor Detail |
public ClientImpl(int _port, java.net.InetAddress _address)
_port
- The port on wich the client will bind to (on wich the server is listening)._address
- The address on wich the client will bind to (on wich the server is listening).Method Detail |
public void onRequest(byte[] _data) throws java.lang.IllegalStateException, InvalidRequestException
onRequest
in interface Client
_data
- The data received from the server.
java.lang.IllegalStateException
- If the client is not running.
InvalidRequestException
- If the request received from the server is not valid.Client.fireEvent(ClientEvent)
public void doRequest(byte[] _data) throws java.lang.IllegalStateException, InvalidRequestException
doRequest
in interface Client
_data
- The answer to send to the server.
java.lang.IllegalStateException
- If the client is not running.
InvalidRequestException
- If the request received from the server is not valid.public void startClient()
startClient
in interface Client
public void stopClient()
stopClient
in interface Client
public boolean isRunning()
isRunning
in interface Client
boolean
- True if the client is running, false otherwise.public void run()
run
in interface java.lang.Runnable
public void setSocketFactory(javax.net.SocketFactory _factory) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException
setSocketFactory
in interface Client
_factory
- The socket factory.
java.lang.IllegalStateException
- If the client is running.
java.lang.IllegalArgumentException
- If the SocketFactory is not valid or has not been initialized.public void addClientListener(ClientListener _listener)
addClientListener
in interface Client
_listener
- The Listener to add.public void removeClientListener(ClientListener _listener)
removeClientListener
in interface Client
_listener
- The Listener to remove.public void removeAllClientListener()
removeAllClientListener
in interface Client
public void fireEvent(ClientEvent _evt)
fireEvent
in interface Client
_evt
- The event to be fired.public java.lang.String getInfo()
getInfo
in interface Client
String
- The client's informations.public java.lang.String getStatus()
getStatus
in interface Client
String
- The client's status.public java.lang.String toString()
toString
in interface Client
toString
in class java.lang.Object
String
- A string representation of this client.public int getPort()
getPort
in interface Client
int
- The port number to which this client is bounded to.public void setPort(int _port) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException
setPort
in interface Client
_port
- The new client's port.
java.lang.IllegalStateException
- If the client is running.
java.lang.IllegalArgumentException
- If the port is not valid.public java.net.InetAddress getInetAddress()
getInetAddress
in interface Client
InetAddress
- A InetAddress representing the address of the server this client is bouded to.public void setInetAddress(java.net.InetAddress _address) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException
setInetAddress
in interface Client
_address
- The new server's address.
java.lang.IllegalStateException
- If the client is running.
java.lang.IllegalArgumentException
- If the address is not valid.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |