|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpictionary.pictionaryclient.PictionaryClient
public final class PictionaryClient
Implementation of a basic Pictionary Client
which handles communication with a PictionaryServer
.
Uses the private class PictionaryClient.ServerConnection
for the actual communication with the server.
PictionaryClient's job is to handle communication with the server and just forward information to
an IPictionaryClientCallback
.
Nested Class Summary | |
---|---|
private class |
PictionaryClient.ServerConnection
ServerConnection handles communication with the PictionaryServer . |
Field Summary | |
---|---|
private IPictionaryClientCallback |
callback
The IPictionaryClientCallback , in this case PictionaryClientGUI . |
java.util.List<java.lang.String> |
connectedClients
A collection containing the connected client's unique names. |
private PictionaryClient.ServerConnection |
connection
Represents the network connection to the server. |
private java.lang.String |
serverHostName
The server's host name. |
private int |
serverPort
The server's port. |
Constructor Summary | |
---|---|
PictionaryClient(java.lang.String serverHostName,
int serverPort)
The constructor. |
Method Summary | |
---|---|
void |
broadcastChatMessage(java.lang.String message)
Creates and sends a Message of the type Message.MessageType.ClientMessageBroadcast
using PictionaryClient.ServerConnection.send(Message) . |
void |
broadcastDraw(java.awt.Point p)
Creates and sends a Message of the type Message.MessageType.DrawData
using PictionaryClient.ServerConnection.send(Message) . |
void |
connect(IPictionaryClientCallback callback)
Creates a new PictionaryClient.ServerConnection using serverHostName and serverPort . |
void |
disconnect()
Sends a message to the server, informing it that we are about to disconnect from it. |
java.lang.String |
getID()
Gets this client unique ID, used by the server to identify it. |
java.lang.String |
getServerInfo()
Gets information about the server's hostname and port, this method is used by PictionaryClientGUI
when setting the client's window title. |
void |
guess(java.lang.String guess)
Creates and sends a Message of the type Message.MessageType.Guess
using PictionaryClient.ServerConnection.send(Message) . |
void |
joinGame()
Sends a message to the server, informing it that we want to join a game of Pictionary. |
private void |
send(Message message)
Sends a Message to the server using PictionaryClient.ServerConnection.send(Message) . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public java.util.List<java.lang.String> connectedClients
private PictionaryClient.ServerConnection connection
private java.lang.String serverHostName
private int serverPort
private IPictionaryClientCallback callback
IPictionaryClientCallback
, in this case PictionaryClientGUI
.
Constructor Detail |
---|
public PictionaryClient(java.lang.String serverHostName, int serverPort)
serverHostName
- The server's host name, this is used when connecting to the server.serverPort
- The server's port, this is used when connecting to the server.Method Detail |
---|
public void connect(IPictionaryClientCallback callback) throws java.io.IOException
PictionaryClient.ServerConnection
using serverHostName
and serverPort
.
callback
- The IPictionaryClientCallback
which will be notified of events.
java.io.IOException
- If the connection to the server could not be established.public void joinGame()
public void disconnect()
private void send(Message message) throws java.lang.IllegalStateException
Message
to the server using PictionaryClient.ServerConnection.send(Message)
.
message
- The message to be sent to the server.
java.lang.IllegalStateException
- If connection
's boolean PictionaryClient.ServerConnection.closed
equals true.public void broadcastChatMessage(java.lang.String message)
Message
of the type Message.MessageType.ClientMessageBroadcast
using PictionaryClient.ServerConnection.send(Message)
.
message
- The Message to be sent.public void guess(java.lang.String guess)
Message
of the type Message.MessageType.Guess
using PictionaryClient.ServerConnection.send(Message)
.
guess
- The word that was guessed by the player.public void broadcastDraw(java.awt.Point p)
Message
of the type Message.MessageType.DrawData
using PictionaryClient.ServerConnection.send(Message)
.
p
- The Point
to send to the server.public final java.lang.String getID()
PictionaryClient.ServerConnection.id
.public final java.lang.String getServerInfo()
PictionaryClientGUI
when setting the client's window title.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |