client.framework.network
Class ClientSocketCommunicator

java.lang.Object
  extended by client.framework.network.ClientSocketCommunicator
All Implemented Interfaces:
Communicator

public class ClientSocketCommunicator
extends java.lang.Object
implements Communicator

This class is a Communicator object that communicates using SocketConnection or UDPDatagramConnection objects for its communication, dependent of whether the transport protocol in use is TCP or UDP, respectively.

Author:
Martin Jarrett, Eivind Sorteberg

Nested Class Summary
protected  class ClientSocketCommunicator.SenderThread
          Thread responsible for sending messages to the server.
 
Field Summary
protected  ClientSocketCommunicator.SenderThread sender
           
 
Constructor Summary
ClientSocketCommunicator(AbstractGame abstractGame, int packetSize)
          Creates a ClientSocketCommunicator object.
 
Method Summary
 void close()
          Called when the connection is closed.
 boolean connect(java.lang.String[] addresses)
          Connects to the specified address(es).
 void disconnect(java.lang.String[] adresses)
          Not implemented.
 void notifyAboutMessageReceived(java.lang.Object message)
          Called when the receiver thread has received a message.
 void searchForNodes()
          Not implemented.
 void sendMessage(java.lang.Object message, boolean confirm)
          Sends the specified message to the server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sender

protected ClientSocketCommunicator.SenderThread sender
Constructor Detail

ClientSocketCommunicator

public ClientSocketCommunicator(AbstractGame abstractGame,
                                int packetSize)
Creates a ClientSocketCommunicator object.

Parameters:
abstractGame - The model with which the communicator communicates locally
packetSize - The size of the UDP data packets (not used for TCP communication)
Method Detail

connect

public boolean connect(java.lang.String[] addresses)
Connects to the specified address(es). The address(es) needs to specify the protocol to use (socket or datagram), the address(es) to the server(s) and the port number of the server. The format of the address(es) is: ://:. Initialises the sender and receiver threads.

Specified by:
connect in interface Communicator
Parameters:
addresses - The address(es) to connect to.
Returns:
Always true (assumes successful connection).

disconnect

public void disconnect(java.lang.String[] adresses)
Not implemented.

Specified by:
disconnect in interface Communicator
Parameters:
adresses - Not used.

sendMessage

public void sendMessage(java.lang.Object message,
                        boolean confirm)
Sends the specified message to the server.

Specified by:
sendMessage in interface Communicator
Parameters:
message - The message to send.
confirm - Not used in this implementation.

notifyAboutMessageReceived

public void notifyAboutMessageReceived(java.lang.Object message)
Called when the receiver thread has received a message. Forwards this message to the model.

Specified by:
notifyAboutMessageReceived in interface Communicator
Parameters:
message - The message that was received.
See Also:
AbstractGame.notifyAboutMessageReceived(String)

close

public void close()
Called when the connection is closed. In this implementation, this method has no effect.

Specified by:
close in interface Communicator

searchForNodes

public void searchForNodes()
Not implemented.

Specified by:
searchForNodes in interface Communicator