|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.asdf.client.ConnectionHandler
public class ConnectionHandler
ConnectionHandler is a class which connects to the server, queues and sends messages to server. ConnectionHandler also receives messages from server and passes them to gameclients and lobbyclient running on client machine.
| Nested Class Summary | |
|---|---|
static class |
ConnectionHandler.State
|
| Field Summary | |
|---|---|
boolean |
running
|
| Constructor Summary | |
|---|---|
ConnectionHandler(java.lang.String hostAddress,
int port)
Constructor for ConnectionHandler. |
|
| Method Summary | |
|---|---|
void |
breakConnection()
Closes connection. |
void |
registerConnectionObserver(ClientStateObserver observer)
|
boolean |
registerMessageHandler(MessageHandler handler)
Game and lobby clients register their response handlers to ConnectionHandler if they want to receive messages from server. |
void |
run()
Starts the ConnectionHandler. |
void |
runOnce()
Runs ConnectionHandler once. |
void |
send(byte[] data)
Queues data to be send to a server. |
void |
sendMessage(Message msg)
Queues message to be send to server. |
void |
sendRaw(java.nio.ByteBuffer data)
Queues data to be send to the server as it is. |
boolean |
unRegisterMessageHandler(MessageHandler handler)
Removes a registered response handler. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public boolean running
| Constructor Detail |
|---|
public ConnectionHandler(java.lang.String hostAddress,
int port)
throws java.io.IOException
hostAddress - Servers ip address in dot notation for example 98.162.0.27port - Servers port for example 8080
java.io.IOException - if connection could not be established| Method Detail |
|---|
public void registerConnectionObserver(ClientStateObserver observer)
observer - public boolean registerMessageHandler(MessageHandler handler)
handler - Game or lobby clients message handler
public boolean unRegisterMessageHandler(MessageHandler handler)
handler - response handler to be unregistered
public void sendMessage(Message msg)
throws java.io.IOException,
javax.xml.bind.JAXBException
msg - message to be send
java.io.IOException - If connection to server is lost.
javax.xml.bind.JAXBException - If message could not be translated to bytes. This means that the
message did not match our message.xsd schema.
public void send(byte[] data)
throws java.io.IOException
data - data to be written
java.io.IOException - If connection to server is lost.
public void sendRaw(java.nio.ByteBuffer data)
throws java.io.IOException
data - to be written
java.io.IOException - If connection to server is lost.to send data with prepending size of the datapublic void run()
run in interface java.lang.Runnablepublic void runOnce()
public void breakConnection()
throws java.io.IOException
java.io.IOException - if the connection was already closed
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||