|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecttipgame.net.Client
public class Client
This is used to receive and transmit data for consistency. The client sends its information, buts uses all information from the server as the authoritative source. Clients send new mouse and keyboard information when it changes. Clients receive regular updates from the Server via GameConnection. It reads all available mouse and keyboard information and time advances to update the model. Once all information from the server has been read and the model updated, the screen is refreshed. Upon a client connecting, the client receives:
| Nested Class Summary | |
|---|---|
(package private) class |
Client.ReaderThread
reads repeatedly from the server and refreshes the screen. |
| Field Summary | |
|---|---|
private FrameAdvancer |
frameAdvancer
the frameAdvancer is used for updating the model and screen upon receiving server information |
private java.lang.String |
game
the name of the current game |
private int |
id
id of this client. |
private java.io.ObjectInputStream |
in
all connections inbound. |
private boolean |
isPaused
since server communication ceases during a puased game, this variable being set to true means the game is paused (not necessarily lost connections to server) |
Keyboard[] |
keyboard
all of the keyboards of the computers connected |
private Keyboard |
localKeyboard
the Keyboard trapping local keyboard events |
private java.lang.Object |
localMessage
unused and untested |
private Mouse |
localMouse
the Mouse trapping local mouse events |
private java.lang.String |
machine
the domain the server is on |
java.lang.Object[] |
message
current unused and untested |
Mouse[] |
mouse
all of the mouses of the computers connected |
private java.io.ObjectOutputStream |
out
all connections outbound. |
private int |
players
the number of players |
private javax.swing.Timer |
readTimer
the timer used to poll for new server information |
private boolean |
sendPause
pause is toggled by settting sendPause to true |
private java.lang.String |
session
the name of the currently running session |
| Constructor Summary | |
|---|---|
Client(java.lang.String machine,
java.lang.String game,
java.lang.String session,
int players)
sets the domain, game and session name and connects to the server. |
|
| Method Summary | |
|---|---|
void |
connect()
Connects to the server then goes into an infinite loop sending and receiving consistency information from and to the server. |
private void |
connectToServer()
tries to connect to an existing server. |
void |
disconnect()
disconnects and terminates sending and receiving informations to and from the server |
int |
getID()
gets the id of the current client. |
boolean |
isPaused()
determines if the game is currently advancing |
void |
pauseToggle()
if the game was paused, this method will set it running again. |
private boolean |
read()
reads in from the server: current time if the are changed since the last message received it also reads keyboard array mouse array message array |
void |
setFrameAdvancer(FrameAdvancer frameAdvancer)
|
void |
setLocalKeyboard(Keyboard localKeyboard)
|
void |
setLocalMessage(java.lang.Object localMessage)
|
void |
setLocalMouse(Mouse localMouse)
|
private void |
tryToConnect()
tries to connect to the designated machine and port |
private void |
tryToConnect(Server server)
starts piped input and output to the local server |
void |
update(java.util.Observable arg0,
java.lang.Object arg1)
this method is called when there is new information to send to the server. |
private void |
write()
If the game is paused, sends nothing unless it is unpause. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private int id
public Keyboard[] keyboard
public Mouse[] mouse
public java.lang.Object[] message
private Keyboard localKeyboard
private Mouse localMouse
private java.lang.Object localMessage
private FrameAdvancer frameAdvancer
private java.io.ObjectInputStream in
private java.io.ObjectOutputStream out
private javax.swing.Timer readTimer
private java.lang.String game
private java.lang.String session
private java.lang.String machine
private int players
private boolean sendPause
private boolean isPaused
| Constructor Detail |
|---|
public Client(java.lang.String machine, java.lang.String game, java.lang.String session, int players)
machine - the domain of the servergame - the name of the gamesession - the name of the current sessionthe - number of players to wait for (only
used for the first person starting the session)| Method Detail |
|---|
public void setLocalMessage(java.lang.Object localMessage)
localMessage - The localMessage to set.public void setFrameAdvancer(FrameAdvancer frameAdvancer)
frameAdvancer - The frameAdvancer to set.public void setLocalKeyboard(Keyboard localKeyboard)
localKeyboard - The localKeyboard to set.public void setLocalMouse(Mouse localMouse)
localMouse - The localMouse to set.private void tryToConnect() throws java.lang.Exception
java.lang.Exception - if no server is running on the
machine and portprivate void tryToConnect(Server server) throws java.lang.Exception
server - the local server
java.lang.Exception - if the connection cannot be establishedprivate void connectToServer()
private void write() throws java.io.IOException
java.io.IOException - if the connection to the server
is disruptedpublic void pauseToggle()
private boolean read() throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException - if the connection to the server is disupted
java.lang.ClassNotFoundException - if there are class loading problemspublic void connect()
Runnable.run()public void disconnect()
public boolean isPaused()
public int getID()
public void update(java.util.Observable arg0, java.lang.Object arg1)
update in interface java.util.Observerarg0 - not usedarg1 - not usedObserver.update(java.util.Observable, java.lang.Object)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||