|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpictionary.pictionaryclient.PictionaryClient.ServerConnection
private class PictionaryClient.ServerConnection
ServerConnection handles communication with the PictionaryServer
.
It uses two threads for sending and receiving messages; PictionaryClient.ServerConnection.SendThread
and PictionaryClient.ServerConnection.ReceiveThread
.
Nested Class Summary | |
---|---|
private class |
PictionaryClient.ServerConnection.ReceiveThread
Responsible for reading Message s from in
and pass them along to handleMessage(pictionary.message.Message) . |
private class |
PictionaryClient.ServerConnection.SendThread
Responsible for taking Message s from outgoingMessages
and sending them to the server using out . |
Field Summary | |
---|---|
private boolean |
closed
When the connection is closing, closed is set to true. |
private java.lang.String |
id
The clients ID. |
private java.io.ObjectInputStream |
in
The stream used for reading messages from the server. |
private java.io.ObjectOutputStream |
out
The stream used for sending messages to the server. |
private java.util.concurrent.LinkedBlockingQueue<Message> |
outgoingMessages
Messages waiting to be sent to the server by sendThread . |
private PictionaryClient.ServerConnection.ReceiveThread |
receiveThread
The thread that received messages from the server. |
private PictionaryClient.ServerConnection.SendThread |
sendThread
The thread that sends messages to the server. |
private java.net.Socket |
socket
The socket connected to the server. |
Constructor Summary | |
---|---|
PictionaryClient.ServerConnection(java.lang.String host,
int port)
The constructor. |
Method Summary | |
---|---|
private void |
close()
Closes the connection. |
private void |
closedByError(java.lang.String error)
Called when an error occurs, probably in receiveThread or sendThread . |
private void |
handleMessage(Message message)
This method is called when a Message has been received in PictionaryClient.ServerConnection.ReceiveThread . |
private void |
send(Message message)
Simply adds a message to outgoingMessages . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final java.lang.String id
private final java.net.Socket socket
private final java.io.ObjectInputStream in
private final java.io.ObjectOutputStream out
private final PictionaryClient.ServerConnection.SendThread sendThread
private final PictionaryClient.ServerConnection.ReceiveThread receiveThread
private final java.util.concurrent.LinkedBlockingQueue<Message> outgoingMessages
sendThread
.
private volatile boolean closed
Constructor Detail |
---|
PictionaryClient.ServerConnection(java.lang.String host, int port) throws java.io.IOException
host
- The server's hostname.port
- The server's port.
java.io.IOException
- if the socket
could not
be created and connected to the server.Method Detail |
---|
private void close()
private void send(Message message)
outgoingMessages
.
message
- The Message
to be sent to the server.private void closedByError(java.lang.String error)
receiveThread
or sendThread
.PictionaryClient.callback
's IPictionaryClientCallback.closedByError(String)
.
error
- A string describing the error.private void handleMessage(Message message)
Message
has been received in PictionaryClient.ServerConnection.ReceiveThread
.Message.messageType
and takes appropriate action,
for example calling PictionaryClient.callback
's
IPictionaryClientCallback.connectedToServer()
method when a message of the type
Message.MessageType.ServerAcceptedConnection
is received.
message
- The Message that was received from the server.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |