CheckersHost
public class Host
extends java.lang.Object
Constructor | Description |
---|---|
Host(int port) |
Create a host listening on the specified port, and start the message processing thread.
|
Modifier and Type | Method | Description |
---|---|---|
protected void |
clientConnected(int clientID) |
Called after a new client has connected
|
protected void |
clientDisconnected(int clientID) |
Called when a client disconnects
|
protected void |
extraHandshake(int clientID,
java.io.ObjectInputStream in,
java.io.ObjectOutputStream out) |
Called after a connection is received to handle extra set up.
|
boolean |
getAutoreset() |
Return the value of the autoreset property
|
int[] |
getClientList() |
Get a list of ID numbers of the clients that are currently connected.
|
protected void |
messageReceived(int clientID,
java.lang.Object message) |
Called when a message is received by a client.
|
void |
resetOutput() |
Reset all output streams after any messages currently in the output queue have been sent.
|
void |
restartServer(int port) |
Restarts listening and accepting new clients
|
void |
sendToAll(java.lang.Object message) |
Sends a specified Object as a message to all connected clients.
|
boolean |
sendToOne(int clientID,
java.lang.Object message) |
Sends a specified Object as a message to the client with the specified ID.
|
void |
setAutoreset(boolean auto) |
If autoreset is set to true, all output streams will be reset before each transmission.
|
void |
shudownHost() |
Disconnect all currently connected clients and stop accepting new clients.
|
void |
shutdownServerSocket() |
Stops listening without dropping connections.
|
public Host(int port) throws java.io.IOException
port
- The port to listen onjava.io.IOException
- if it is not possible to create a listening socket on the specified portprotected void messageReceived(int clientID, java.lang.Object message)
clientID
- The ID of the client the message is frommessage
- The actual message that was sentprotected void clientConnected(int clientID)
clientID
- The ID of the new clientprotected void clientDisconnected(int clientID)
clientID
- The ID of the client that disconnectedprotected void extraHandshake(int clientID, java.io.ObjectInputStream in, java.io.ObjectOutputStream out) throws java.io.IOException
clientID
- The id of the client to shake hands within
- The stream from which messages from the client can be readout
- The stream that messages to the client can be sentjava.io.IOException
- if there is a problem with the connection. The connection will be closed and the client
never added to the list.public int[] getClientList()
public void shutdownServerSocket()
public void restartServer(int port) throws java.io.IOException
port
- The port to listen onjava.io.IOException
- if it is not possible to create a socket on the specified portpublic void shudownHost()
public void sendToAll(java.lang.Object message)
message
- The message to send to all clients. It must implement the Serializable interface and
must not be null.public boolean sendToOne(int clientID, java.lang.Object message)
clientID
- The ID of the client to send the message tomessage
- The message to send to the client. Must implement the serializable interface and must not be null.public void resetOutput()
public void setAutoreset(boolean auto)
auto
- The value to set autoreset topublic boolean getAutoreset()