|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpictionary.PictionaryPlayer
pictionary.pictionaryserver.PictionaryServer.ClientConnection
private class PictionaryServer.ClientConnection
Handles communication with one client; there is one ClientConnection per connected client.
Also extends PictionaryPlayer
so it can be used with PictionaryServer.pictionaryGame
.
Has one thread for receiving messages from the client and one for sending messages.
Nested Class Summary | |
---|---|
private class |
PictionaryServer.ClientConnection.ReceiveThread
Receives messages from the client and adds them to the server's message queue. |
private class |
PictionaryServer.ClientConnection.SendThread
Initially handles setup, then takes care of sending messages to the client. |
Field Summary | |
---|---|
private java.lang.String |
clientID
The clients unique identifier, a String containing it's name. |
private boolean |
closed
Is set to true if the client should be disconnected gracefully. |
private java.net.Socket |
connection
The Socket used for getting the in and output streams. |
private java.io.ObjectInputStream |
in
The stream used for reading messages from the client. |
private java.util.concurrent.BlockingQueue<PictionaryServer.ClientConnectionMessage> |
incomingMessages
Received messages are put in this collection, this is a reference to PictionaryServer.incomingMessages . |
private java.io.ObjectOutputStream |
out
The stream used for sending messages to the client. |
private java.util.concurrent.LinkedBlockingQueue<Message> |
outgoingMessages
A collection of messages waiting to be sent to the client. |
private java.lang.Thread |
receiveThread
Takes care of receiving and forwarding messages from the client to the server. |
private java.lang.Thread |
sendThread
The PictionaryServer.ClientConnection.SendThread instance. |
Fields inherited from class pictionary.PictionaryPlayer |
---|
DRAWING, SPECTATING, WAITING_FOR_TURN |
Constructor Summary | |
---|---|
PictionaryServer.ClientConnection(java.util.concurrent.BlockingQueue<PictionaryServer.ClientConnectionMessage> receivedMessageQueue,
java.net.Socket connection)
The constructor. |
Method Summary | |
---|---|
private void |
close()
Closes this connection and terminates the send and receive threads. |
private void |
closedWithError(java.lang.String message)
Sends the message to PictionaryServer.connectionToClientClosedWithError(ClientConnection, String)
and calls close() . |
void |
correctGuess(java.lang.String guess)
Informs the player that he made a correct guess. |
void |
correctGuessBroadcast(java.lang.String clientID,
java.lang.String guess)
Informs the player that a player made a correct guess. |
void |
gameStarted()
Informs the player that a new game of Pictionary has started. |
java.lang.String |
getClientID()
Get method for clientID . |
void |
playerStartedDrawing(java.lang.String clientID)
Informs the player that a player started drawing. |
void |
playerStoppedDrawing(java.lang.String clientID)
Informs the player that a player stopped drawing. |
void |
reportScores(java.util.List<java.lang.String> players,
java.util.List<java.lang.Integer> scores)
Reports the players' scores. |
void |
send(Message message)
Adds a message to outgoingMessages . |
void |
startDraw(java.lang.String wordToDraw)
Informs the player that it is her turn to start drawing a word. |
void |
startGuessing()
Informs the player that it can start guessing on the word being drawn. |
void |
stopDraw()
Informs the player that its draw turn is over. |
void |
stopGuessing()
Informs the player that the guessing turn is over. |
void |
tellWord(java.lang.String word)
Tells the player the last word. |
void |
wrongGuess(java.lang.String clientID,
java.lang.String guess)
Informs the player that someone made an incorrect guess. |
Methods inherited from class pictionary.PictionaryPlayer |
---|
equals, getScore, getStatus, setScore, setStatus |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.lang.String clientID
private java.util.concurrent.BlockingQueue<PictionaryServer.ClientConnectionMessage> incomingMessages
PictionaryServer.incomingMessages
.
private java.util.concurrent.LinkedBlockingQueue<Message> outgoingMessages
private java.net.Socket connection
private java.io.ObjectInputStream in
private java.io.ObjectOutputStream out
private volatile boolean closed
private java.lang.Thread sendThread
PictionaryServer.ClientConnection.SendThread
instance.
private volatile java.lang.Thread receiveThread
Constructor Detail |
---|
public PictionaryServer.ClientConnection(java.util.concurrent.BlockingQueue<PictionaryServer.ClientConnectionMessage> receivedMessageQueue, java.net.Socket connection)
receivedMessageQueue
- The queue where received messages will be put.connection
- The Socket that will be used to get streams from.Method Detail |
---|
public java.lang.String getClientID()
clientID
.
getClientID
in class PictionaryPlayer
private void close()
public void send(Message message)
outgoingMessages
.
message
- The message to be sent.private void closedWithError(java.lang.String message)
PictionaryServer.connectionToClientClosedWithError(ClientConnection, String)
and calls close()
.
message
- The message to be printed.public void stopDraw()
PictionaryPlayer
stopDraw
in class PictionaryPlayer
public void playerStoppedDrawing(java.lang.String clientID)
PictionaryPlayer
playerStoppedDrawing
in class PictionaryPlayer
clientID
- The name of the player that stopped drawing.public void startDraw(java.lang.String wordToDraw)
PictionaryPlayer
startDraw
in class PictionaryPlayer
wordToDraw
- The word that the player should attempt to draw.public void playerStartedDrawing(java.lang.String clientID)
PictionaryPlayer
playerStartedDrawing
in class PictionaryPlayer
clientID
- The name of the player that started drawing.public void gameStarted()
PictionaryPlayer
gameStarted
in class PictionaryPlayer
public void correctGuess(java.lang.String guess)
PictionaryPlayer
correctGuess
in class PictionaryPlayer
guess
- The guess that was correct.public void correctGuessBroadcast(java.lang.String clientID, java.lang.String guess)
PictionaryPlayer
correctGuessBroadcast
in class PictionaryPlayer
clientID
- The player that made the guess.guess
- The correct word.public void startGuessing()
PictionaryPlayer
startGuessing
in class PictionaryPlayer
public void stopGuessing()
PictionaryPlayer
stopGuessing
in class PictionaryPlayer
public void wrongGuess(java.lang.String clientID, java.lang.String guess)
PictionaryPlayer
wrongGuess
in class PictionaryPlayer
clientID
- The player that made the guess.guess
- The incorrect guess.public void reportScores(java.util.List<java.lang.String> players, java.util.List<java.lang.Integer> scores)
PictionaryPlayer
scores
corresponds to the
player at the same index in players
.
reportScores
in class PictionaryPlayer
players
- A collection of players.scores
- A collection of scores.public void tellWord(java.lang.String word)
PictionaryPlayer
tellWord
in class PictionaryPlayer
word
- The word that was being drawn.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |