|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.eriksilkensen.net.Client
public class Client
An Observable Client that can be used to connect
to Servers.
Observers that register themselves and pushed a reference to this Observable, along with an Object argument. This allows Observers to either accept the push or use a pull to take advantage of the Observable interface.
Specific jobs or functionality for a Client should be implemented by extending this Client.
Note: To remove a Client from the Server
send out a quit message on closing.
This must be done with:
writer.println( Server.QUIT_MESSAGE + name )
Server,
Observer,
Observable| Field Summary | |
|---|---|
protected java.lang.Object |
arg
|
protected boolean |
changed
|
protected java.util.List<Observer> |
observers
|
| Constructor Summary | |
|---|---|
Client()
Default constructor that initializes the List of Observers, clears changed. |
|
Client(java.lang.String host,
int port)
Constructs a Client with the specified host and port configuration. |
|
| Method Summary | |
|---|---|
void |
clearChanged()
Clears this Client of being "changed" |
void |
clearConnected()
Clears this Client of being connected |
void |
clearHost()
Clears this Client from being a host |
void |
clearInit()
Clears this Client from being initialized |
java.lang.String |
getHost()
|
protected IncomingReader |
getIncomingReader(java.lang.String name)
Returns a new instance of an IncomingReader that will handle all of the incoming messages. |
java.lang.String |
getName()
|
int |
getPort()
|
protected java.io.BufferedReader |
getReader()
Returns this Client's reader. |
java.lang.String |
getRealName()
|
boolean |
hasInit()
Returns whether or not this Client has been initialized |
void |
init(java.lang.String name)
Initializes this Client by setting up networking, and starting the Reader Thread. |
boolean |
isConnected()
Returns whether or not this Client is connected |
boolean |
isHost()
Returns whether or not this Client is a host |
void |
notifyObservers()
Notifiies Observers. |
void |
quit()
Disconnects this Client from the Server by sending out a special 'quit' message telling the Server to remove it from its List of Clients. |
void |
registerObserver(Observer obs)
Registers an Observer with the List of observers |
void |
removeObserver(Observer obs)
Removes an Observer from the List of observers |
void |
sendMessage(java.lang.String message)
Sends a message. |
void |
setArg(java.lang.Object arg)
Sets the optional Object arg that gets pushed to Observers when they are notified of a change |
void |
setChanged()
Sets this Client to be "changed" |
void |
setConnected()
Sets this Client to be connected |
void |
setHost()
Sets this Client to be a host |
void |
setHost(java.lang.String host)
Sets this Client's host configuration |
void |
setPort(int port)
Sets this Client's port configuration |
protected void |
setUpNetworking()
Sets up the networking by creating a Socket and attempting to connect to the Server. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected boolean changed
protected java.lang.Object arg
protected java.util.List<Observer> observers
| Constructor Detail |
|---|
public Client()
Default constructor that initializes the List of Observers, clears changed.
The default host and port are set to 127.0.0.1 and 5000, respectively. Before the Client can be used it must run its init() method. This must be done manually by whichever class wants to use it.
public Client(java.lang.String host,
int port)
| Method Detail |
|---|
public void removeObserver(Observer obs)
removeObserver in interface Observableobs - the Observer to removepublic void registerObserver(Observer obs)
registerObserver in interface Observableobs - the Observer to registerpublic void notifyObservers()
notifyObservers in interface Observablepublic void setChanged()
public void clearChanged()
public void setArg(java.lang.Object arg)
arg - the arg
public void init(java.lang.String name)
throws NotConnectedException
NotConnectedException
protected IncomingReader getIncomingReader(java.lang.String name)
throws NotConnectedException
NotConnectedExceptionpublic boolean hasInit()
public void clearInit()
public boolean isConnected()
public void setConnected()
public void clearConnected()
public boolean isHost()
public void setHost()
public void clearHost()
public void setHost(java.lang.String host)
public void setPort(int port)
protected void setUpNetworking()
throws NotConnectedException
NotConnectedExceptionpublic void sendMessage(java.lang.String message)
message - the message to sendpublic void quit()
protected java.io.BufferedReader getReader()
throws NotConnectedException
NotConnectedExceptionpublic java.lang.String getName()
public java.lang.String getRealName()
public java.lang.String getHost()
public int getPort()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||