public abstract class Client
extends java.lang.Object
Modifier and Type | Field | Description |
---|---|---|
protected int[] |
connectedClientIDs |
A list of the IDs of all clients who are currently connected to the host.
|
Constructor | Description |
---|---|
Client(java.lang.String hostName,
int hostPort) |
Constructor that creates a connection to the host.
|
Modifier and Type | Method | Description |
---|---|---|
protected void |
clientConnected(int newPlayerID) |
Called when this client is notified that a client has connected to the host.
|
protected void |
clientDisconnected(int departingPlayerID) |
Called when this client is notified that another client has disconnected from the host.
|
protected void |
connectionClosedByError(java.lang.String message) |
Called when the connection to the host is closed due to an error.
|
void |
disconnect() |
Disconnect cleanly from the host.
|
protected void |
extraHandshake(java.io.ObjectInputStream in,
java.io.ObjectOutputStream out) |
Called after connection to the host is opened and after the client is assigned an ID number.
|
boolean |
getAutoreset() |
Return the value of the autoreset property
|
int |
getID() |
Return the ID of this client that was assigned when the connection was established.
|
protected abstract void |
messageReceived(java.lang.Object message) |
Called when a message is received from the host.
|
void |
resetOutput() |
Resets the output stream, after any messages currently in the output queue have been sent.
|
void |
send(java.lang.Object message) |
Add a message to the queue to be sent to the host.
|
protected void |
serverShutdown(java.lang.String message) |
Called when the connectino to the host is shutdown because the server is shutting down.
|
void |
setAutoreset(boolean auto) |
Set the autoreset property, which determines if output streams will be reset before every transmission.
|
protected int[] connectedClientIDs
public Client(java.lang.String hostName, int hostPort) throws java.io.IOException
hostName
- The ip address of the hosthostPort
- The port the host is listening to for connection requestsjava.io.IOException
- if any problems occur when trying to connectprotected abstract void messageReceived(java.lang.Object message)
message
- The received messageprotected void clientConnected(int newPlayerID)
newPlayerID
- The ID of the newly connected clientprotected void clientDisconnected(int departingPlayerID)
departingPlayerID
- The ID of the client who has disconnectedprotected void connectionClosedByError(java.lang.String message)
message
- An error messageprotected void serverShutdown(java.lang.String message)
message
- A good message sent by the host that it is being shutdown properly (without error)protected void extraHandshake(java.io.ObjectInputStream in, java.io.ObjectOutputStream out) throws java.io.IOException
in
- A stream that messages from the host can be read fromout
- A stream that messages to the host can be sent withjava.io.IOException
public void disconnect()
public void send(java.lang.Object message) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
message
- The Object message to send to the host, must implement Serializable and cannot be nulljava.lang.IllegalArgumentException
- If the message is null or does not implement Serializablejava.lang.IllegalStateException
- If the connection to the host is closedpublic int getID()
public void resetOutput()
public void setAutoreset(boolean auto)
auto
- True or Falsepublic boolean getAutoreset()