|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecttipgame.net.GameConnections
public class GameConnections
This is used to receive and transmit data for consistency. The server is the authority of all information. The server sends regular updates and sends a common clock sample. Upon a client connecting, the server sends:
| Nested Class Summary | |
|---|---|
(package private) class |
GameConnections.WriterThread
repeatedly writes to the clients |
| Field Summary | |
|---|---|
private boolean[] |
activeStreams
the state of the game connections to the server. |
private double |
currentTime
the global clock time in seconds. |
private java.lang.String |
gameName
name of the game |
private boolean |
hasReadClients
dirty bit indicating if the server has read new information from the clients. |
protected java.io.ObjectInputStream[] |
in
all connections inbound. |
private boolean |
isPaused
the state of the advancing of the game |
private Keyboard[] |
keyboard
all of the keyboards of the computers connected |
private java.lang.Object[] |
message
currently unused |
private Mouse[] |
mouse
all of the mouses of the computers connected |
private java.io.ObjectOutputStream[] |
out
all connections outbound. |
private java.lang.String |
sessionName
name of this session |
static int |
TIME_BETWEEN_UPDATES
time between sending updates to the clients |
private java.util.Timer |
timer
used to repeatedly write to the clients |
| Constructor Summary | |
|---|---|
GameConnections(java.lang.String gameName,
java.lang.String sessionName,
int players)
constructs a server without blocking. |
|
| Method Summary | |
|---|---|
boolean |
addConnection(java.io.ObjectOutputStream outStream,
java.io.ObjectInputStream inStream)
adds a connection to the server's list of clients. |
private void |
clearInputDevices()
clears all keys typed and mouses clicked to make sure they are only sent once. |
private void |
flushClients()
flushes what's currently in the output streams to the clients. |
private int |
getFirstInactiveStream()
determines where the next active stream should be added |
private void |
handleBrokenConnection(int clientIndex)
handles exceptions of broken connections. |
boolean |
isActive()
determines if any stream is active |
boolean |
isFull()
determines if all connections are alive |
private void |
keepThreadAlive()
necessary to keep the timer alive |
private void |
readAvailable()
reads any available new information from the clients. |
boolean |
readAvailable(int clientIndex)
reads what's available from the given client without blocking |
private void |
sendFirstClientMessage()
sends the information the client needs to start communications: keyboard array mouse array message array This method sends the arrays as complete objects the first time so that the existing objects can simply be updated on later transmissions. |
void |
startThreads()
starts the writing to the clients. |
void |
write()
writes to all clients if the game is not paused |
private void |
writeClient(int clientIndex)
writes an update to the client. |
private void |
writeClients()
writes an update to all client. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private Keyboard[] keyboard
private Mouse[] mouse
private boolean isPaused
public static final int TIME_BETWEEN_UPDATES
private java.lang.Object[] message
private java.util.Timer timer
private boolean hasReadClients
protected java.io.ObjectInputStream[] in
private java.io.ObjectOutputStream[] out
private boolean[] activeStreams
private java.lang.String gameName
private java.lang.String sessionName
private double currentTime
| Constructor Detail |
|---|
public GameConnections(java.lang.String gameName, java.lang.String sessionName, int players)
gameName - the name of the game being playedsessionName - the name of the current session for a given gameplayers - the number of clients connecting| Method Detail |
|---|
public boolean isFull()