|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.isi.gamebots.client.GamebotsClient
This class is a JavaBean client for the Gamebots server. It encapsulates
the lowest level network connection and provides an EventListener interface
GamebotsClient.Listener
to handle incoming server messages.
Nested Class Summary | |
static class |
GamebotsClient.Adapter
Simple implementation of a GamebotsClient.Listener . |
static interface |
GamebotsClient.Listener
Interface for listening to a GamebotsClient . |
protected class |
GamebotsClient.PingTask
|
Nested classes inherited from class edu.isi.gamebots.client.GamebotsConstants |
GamebotsConstants.TeamColorMap |
Field Summary | |
protected static int |
BUFFER_LENGTH
Length of the socket read buffer. |
protected Object |
connectionLock
Synchronization lock for manipulating the connection. |
protected Thread |
inputThread
Thread used to handle incoming messages from the server. |
protected long |
lastMessageTime
Time of the last received message. |
protected List |
listeners
List of registered GamebotsClient.Listener s. |
protected static int |
MAX_WAIT
|
protected PrintWriter |
output
The outgoing wruter . |
protected Object |
outputLock
Synchronization lock for manipulating the outgoing connection. |
protected GamebotsClient.PingTask |
pingTask
The current PingTask on the pingTimer detect dropped connections. |
protected Timer |
pingTimer
A timer used to detect dropped connections. |
protected Socket |
socket
The network connection socket. |
Fields inherited from interface edu.isi.gamebots.client.GamebotsConstants |
ACTOR_CLASS, ACTOR_ID, ACTOR_REACHABLE, ARG_ALT, ARG_AMOUNT, ARG_GLOBAL, ARG_TARGET, ARG_TEXT, ARG_WALK, BEG, BUMP, CHANGEWEAPON, CHECKREACH, DAMAGE, DEATH_DAMAGE_TYPE, DEATH_KILLER, DEFAULT_BOT_PORT, DEFAULT_VIZ_PORT, DIE, DOM, DOMPOINTS, END, FALSE, FINISHED, GAMESTATE, GETPATH, INFO, INIT, INV, ITEM, ITEM_ID, JUMP, KILL, LOCATION, MESSAGE, MOV, NAV, NODE_DOMINATION, NODE_INVENTORY, NODE_MOVER, NODE_NAVIGATION, OWNER, PATH, PING, PLAYER, PLAYER_AMMO, PLAYER_ARMOR, PLAYER_HEALTH, PLAYER_NAME, PLAYER_RADIUS, PLAYER_TEAM, PLAYER_WEAPON, PONG, ROTATE, ROTATION, RUNTO, SEE, SELF, SETWALK, SHOOT, STOP, STOP_SHOOT, STRAFE, TEAM_ANY, TEAM_BLUE, TEAM_GOLD, TEAM_GREEN, TEAM_NONE, TEAM_RED, TRUE, TURNTO, VELOCITY, WALL, WEAPON_1, WEAPON_2 |
Constructor Summary | |
GamebotsClient()
|
Method Summary | |
void |
addListener(GamebotsClient.Listener listener)
Registers a GamebotsClient.Listener with this client. |
void |
connect()
Initiates a connection to the server. |
void |
disconnect()
Disconnects the client from the server. |
protected void |
fireConnected()
|
protected void |
fireDisconnected()
|
protected void |
fireReceivedSocketError(Throwable error)
Passes given network error to all registered GamebotsClient.Listener s. |
long |
getLastMessageReceivedTimeStamp()
Gets the timestamp of the last message received from the server. |
boolean |
getLogOutput()
|
InetAddress |
getServerAddress()
|
int |
getServerPort()
|
protected void |
handleSocket(Socket socket)
Manages incoming network stream, and sends incoming Messages to registered GamebotsClient.Listener s. |
boolean |
isConnected()
|
protected Message |
parseMessage(Reader in)
Builds Message objects out of the PushbackReader in. |
void |
ping()
|
void |
removeListener(GamebotsClient.Listener listener)
Unregisters listener with this client. |
boolean |
sendMessage(String msg)
Sends a string message to the server |
boolean |
sendMessage(String type,
Properties properties)
Sends a message to the server with the given type and properties. |
void |
setLog(us.ca.la.anm.util.io.DebugLog log)
Sets the DebugLog used to log events. |
void |
setLogOutput(boolean logOutput)
Sets whether outgoing messages are logged. |
void |
setServerAddress(InetAddress serverAddress)
Sets the internet address of the Gamebots server. |
void |
setServerPort(int port)
Sets the network port of the Gamebots server. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final int BUFFER_LENGTH
parseMessage(java.io.Reader)
.
protected static final int MAX_WAIT
protected final Object connectionLock
protected Socket socket
protected Thread inputThread
protected final Object outputLock
protected PrintWriter output
protected List listeners
GamebotsClient.Listener
s.
protected long lastMessageTime
protected Timer pingTimer
protected GamebotsClient.PingTask pingTask
pingTimer
detect dropped connections.
Constructor Detail |
public GamebotsClient()
Method Detail |
public void setLog(us.ca.la.anm.util.io.DebugLog log)
DebugLog
used to log events. If never set, events will
be logged to PrintWriterLog.DEFAULT
.
public boolean getLogOutput()
public void setLogOutput(boolean logOutput)
setLog(us.ca.la.anm.util.io.DebugLog)
public long getLastMessageReceivedTimeStamp()
public void addListener(GamebotsClient.Listener listener)
GamebotsClient.Listener
with this client.
Does nothing if the listener is already registered.
public void removeListener(GamebotsClient.Listener listener)
listener
with this client.
Does nothing if the listener is not currently registered.
public InetAddress getServerAddress()
public void setServerAddress(InetAddress serverAddress)
IllegalArgumentException
- if serverAddress is null.public int getServerPort()
GamebotsConstants.DEFAULT_BOT_PORT
.public void setServerPort(int port)
IllegalStateException
- is client is currently connected.
IllegalArgumentException
- if port <= 0.public boolean isConnected()
public void connect() throws IOException
IOException
- if socket cannot be created.
IllegalStateException
- if the server address is not set.public boolean sendMessage(String msg)
public boolean sendMessage(String type, Properties properties)
IllegalArgumentException
- if type is null or empty.setLogOutput(boolean)
public void ping()
public void disconnect()
protected void handleSocket(Socket socket)
GamebotsClient.Listener
s.
protected Message parseMessage(Reader in) throws IOException
Message
objects out of the PushbackReader in.
IOException
- caused by in.read(...)protected void fireConnected()
protected void fireReceivedSocketError(Throwable error)
GamebotsClient.Listener
s.
protected void fireDisconnected()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |