@@ -0,0 +1,2201 @@
+/**%0A * %0A */%0Apackage com.example.crystalgame.communication;%0A%0Aimport java.io.IOException;%0Aimport java.io.ObjectInputStream;%0Aimport java.io.ObjectOutputStream;%0Aimport java.net.Socket;%0Aimport java.net.UnknownHostException;%0A%0Aimport android.util.Log;%0A%0Aimport com.example.crystalgame.library.communication.CommunicationFailureException;%0Aimport com.example.crystalgame.library.communication.CommunicationManager;%0Aimport com.example.crystalgame.library.communication.ConnectionHandler;%0A%0A/**%0A * Client side implementation of %7B@link CommunicationManager%7D%0A * %0A * @author Balazs Pete, Allen Thomas Varghese%0A *%0A */%0Apublic class ClientCommunicationManager extends CommunicationManager %7B%0A%0A%09private Socket socket;%0A%09private ConnectionHandler handler;%0A%09%0A%09private String address;%0A%09private int port;%0A%09%0A%09public ClientCommunicationManager(String address, int port) %7B%0A%09%09this.address = address;%0A%09%09this.port = port;%0A%09%7D%0A%09%0A%09@Override%0A%09public void sendData(String id, String data)%0A%09%09%09throws CommunicationFailureException %7B%0A%09%09// TODO Auto-generated method stub%0A%09%09if (handler == null) %7B%0A%09%09%09throw CommunicationFailureException.FAILED_TO_TRANSMIT;%0A%09%09%7D%0A%09%09%0A%09%09handler.send(data);%0A%09%09Log.d(%22ClientCommunicationManager%22, %22Sent message to %22 + address);%0A%09%7D%0A%09%0A%09@Override%0A%09public void run() %7B%0A%09%09while (true) %7B%0A%09%09%09socket = null;%0A%09%09%09handler = null;%0A%0A%09%09%09try %7B%0A%09%09%09%09Log.i(%22ComunicationManager%22, %22Attempting to connect to %22 + address);%0A%09%09%09%09%0A%09%09%09%09socket = new Socket(address, port);%0A%09%09%09%09handler = new ConnectionHandler(this.abstraction, %22%22, socket);%0A%09%09%09%09Log.i(%22ComunicationManager%22, %22Connection to %22 + address + %22successful!%22);%0A%09%09%09%09handler.run();%0A%09%09%09%7D catch (UnknownHostException e) %7B%0A%09%09%09%09Log.e(%22ClientCommunicationManager%22, %22Connection failed, unknown remote %22 + address);%0A%09%09%09%7D catch (IOException e) %7B%0A%09%09%09%09Log.e(%22ClientCommunicationManager%22, %22Failed to open connection to %22 + address);%0A%09%09%09%7D finally %7B%0A%09%09%09%09if (socket != null) %7B%0A%09%09%09%09%09try %7B%0A%09%09%09%09%09%09socket.close();%0A%09%09%09%09%09%09Log.i(%22ClientCommunicationManager%22, %22Connection to %22 + address + %22 closed%22);%0A%09%09%09%09%09%7D catch (IOException e) %7B%0A%09%09%09%09%09%09Log.e(%22ClientCommunicationManager%22, %22Connection already closed%22);%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09Log.i(%22ClientCommunicationManager%22, %22No socket to close%22);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%7D%0A

Add CommunicationManager for the client