|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ocsf.client.AbstractClient
The AbstractClient
contains all the
methods necessary to set up the client side of a client-server
architecture. When a client is thus connected to the
server, the two programs can then exchange Object
instances.
Method handleMessageFromServer
must be defined by
a concrete subclass. Several other hook methods may also be
overriden.
Several public service methods are provided to application that use this framework.
Project Name: OCSF (Object Client-Server Framework)
Field Summary | |
private java.lang.Thread |
clientReader
The thread created to read data from the server. |
private java.net.Socket |
clientSocket
Sockets are used in the operating system as channels of communication between two processes. |
private java.lang.String |
host
The server's host name. |
private java.io.ObjectInputStream |
input
The stream to handle data from the server. |
private java.io.ObjectOutputStream |
output
The stream to handle data going to the server. |
private int |
port
The port number. |
private boolean |
readyToStop
Indicates if the thread is ready to stop. |
Constructor Summary | |
AbstractClient(java.lang.String host,
int port)
Constructs the client. |
Method Summary | |
private void |
closeAll()
Closes all aspects of the connection to the server. |
void |
closeConnection()
Closes the connection to the server. |
protected void |
connectionClosed()
Hook method called after the connection has been closed. |
protected void |
connectionEstablished()
Hook method called after a connection has been established. |
protected void |
connectionException(java.lang.Exception exception)
Hook method called each time an exception is thrown by the client's thread that is waiting for messages from the server. |
java.lang.String |
getHost()
|
java.net.InetAddress |
getInetAddress()
returns the client's description. |
int |
getPort()
|
protected abstract void |
handleMessageFromServer(java.lang.Object msg)
Handles a message sent from the server to this client. |
boolean |
isConnected()
|
void |
openConnection()
Opens the connection with the server. |
void |
run()
Waits for messages from the server. |
void |
sendToServer(java.lang.Object msg)
Sends an object to the server. |
void |
setHost(java.lang.String host)
Sets the server host for the next connection. |
void |
setPort(int port)
Sets the server port number for the next connection. |
Methods inherited from class java.lang.Object |
|
Field Detail |
private java.net.Socket clientSocket
Socket
private java.io.ObjectOutputStream output
private java.io.ObjectInputStream input
private java.lang.Thread clientReader
private boolean readyToStop
private java.lang.String host
private int port
Constructor Detail |
public AbstractClient(java.lang.String host, int port)
host
- the server's host name.port
- the port number.Method Detail |
public final void openConnection() throws java.io.IOException
public final void sendToServer(java.lang.Object msg) throws java.io.IOException
msg
- The message to be sent.public final void closeConnection() throws java.io.IOException
public final boolean isConnected()
public final int getPort()
public final void setPort(int port)
port
- the port number.public final java.lang.String getHost()
public final void setHost(java.lang.String host)
host
- the host name.public final java.net.InetAddress getInetAddress()
public final void run()
handleMessageFromServer()
.
Not to be explicitly called.protected void connectionClosed()
protected void connectionException(java.lang.Exception exception)
exception
- the exception raised.protected void connectionEstablished()
protected abstract void handleMessageFromServer(java.lang.Object msg)
msg
- the message sent.private void closeAll() throws java.io.IOException
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |