diff --git a/ProyectoAndroid/ChessTrack/src/uy/edu/chesstrack/communication/Client.java b/ProyectoAndroid/ChessTrack/src/uy/edu/chesstrack/communication/Client.java index 2d297b38685269761be9c8bd7dc744c3a0d260f2..3636e4a9351c0062dd6f42deb0f809c1b0e0ed07 100644 --- a/ProyectoAndroid/ChessTrack/src/uy/edu/chesstrack/communication/Client.java +++ b/ProyectoAndroid/ChessTrack/src/uy/edu/chesstrack/communication/Client.java @@ -1,67 +1,67 @@ package uy.edu.chesstrack.communication; -import java.io.BufferedWriter; +import java.io.DataOutputStream; import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.net.InetAddress; import java.net.Socket; -import java.net.UnknownHostException; -import android.app.Activity; -import android.os.Bundle; -import android.view.View; -import android.widget.EditText; +import android.util.Log; -public class Client extends Activity { +public class Client { - private Socket socket; + private static final String TAG = "CLIENT"; + private Socket serverSocket; + //private BufferedReader input; + private DataOutputStream output; - private static final int SERVERPORT = 5000; - private static final String SERVER_IP = "10.0.2.2"; + public static final int SERVERPORT = 5555; - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); -// setContentView(R.layout.main); + public Client(String serverIp) { + Log.i(TAG, "init client-server communication"); + try { + InetAddress serverAddr = InetAddress.getByName(serverIp); + serverSocket = new Socket(serverAddr, SERVERPORT); + Log.i(TAG, "Server on " + serverIp + ":" + SERVERPORT); - new Thread(new ClientThread()).start(); + // get stream to send data + this.output = new DataOutputStream(this.serverSocket.getOutputStream()); + this.SendData(new String("Aylen Ricca Cambon\n")); + // get stream to receive data + //this.input = new BufferedReader(new InputStreamReader(this.serverSocket.getInputStream())); + } catch (IOException e) { + e.printStackTrace(); + } } - public void onClick(View view) { + public void SendData(String msg) { try { - // EditText et = (EditText) findViewById(R.id.EditText01); - // String str = et.getText().toString(); - PrintWriter out = new PrintWriter(new BufferedWriter( - new OutputStreamWriter(socket.getOutputStream())), - true); - //out.println(str); - } catch (UnknownHostException e) { - e.printStackTrace(); + Log.i(TAG, "sending="+ msg); + this.output.writeBytes(msg); } catch (IOException e) { e.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); } } - class ClientThread implements Runnable { - - @Override - public void run() { - - try { - InetAddress serverAddr = InetAddress.getByName(SERVER_IP); - - socket = new Socket(serverAddr, SERVERPORT); - - } catch (UnknownHostException e1) { - e1.printStackTrace(); - } catch (IOException e1) { - e1.printStackTrace(); - } - + /* + public String ReceiveData() { + try { + String read = input.readLine(); + Log.i(TAG, "received="+ read); + return read; + } catch (IOException e) { + e.printStackTrace(); + return null; } + } + */ + public void Stop() { + try { + serverSocket.close(); + output.close(); + //input.close(); + } catch (IOException e) { + e.printStackTrace(); + } } -} \ No newline at end of file +} diff --git a/ProyectoAndroid/ChessTrack/src/uy/edu/chesstrack/communication/Server.java b/ProyectoAndroid/ChessTrack/src/uy/edu/chesstrack/communication/Server.java deleted file mode 100644 index 778cf9c3f5b6d761e9daa04db6de888130fc4d25..0000000000000000000000000000000000000000 --- a/ProyectoAndroid/ChessTrack/src/uy/edu/chesstrack/communication/Server.java +++ /dev/null @@ -1,65 +0,0 @@ -package uy.edu.chesstrack.communication; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.UnknownHostException; - -import android.app.Activity; -import android.os.Bundle; -import android.os.Handler; -import android.util.Log; -import android.widget.TextView; - -public class Server { - - private static final String TAG = "SERVER"; - private ServerSocket serverSocket; - private Socket clientSocket; - private BufferedReader input; - private DataOutputStream output; - - public static final int SERVERPORT = 5555; - - public Server(String serverIp) { - clientSocket = null; - try { - serverSocket = new ServerSocket(SERVERPORT); - clientSocket = serverSocket.accept(); - this.input = new BufferedReader(new InputStreamReader(this.clientSocket.getInputStream())); - String read = input.readLine(); - Log.i(TAG, "line="+ read); - - this.output = new DataOutputStream(this.clientSocket.getOutputStream()); - this.output.writeBytes(new String("AYLEN RICCA"));//(read.toCharArray()); - - } catch (IOException e) { - e.printStackTrace(); - } - } - - public void SendData() { - try { - serverSocket.close(); - clientSocket.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public void Stop() { - try { - serverSocket.close(); - clientSocket.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - -} \ No newline at end of file diff --git a/ProyectoAndroid/ChessTrack/src/uy/edu/fing/chesstrack/ChessTrackActivity.java b/ProyectoAndroid/ChessTrack/src/uy/edu/fing/chesstrack/ChessTrackActivity.java index 5de3f1e326bd6dff6222355d44dd1fc35f6956e1..7a0224e79d5aaf25f3d3f5bc4aaa843f9ada6820 100644 --- a/ProyectoAndroid/ChessTrack/src/uy/edu/fing/chesstrack/ChessTrackActivity.java +++ b/ProyectoAndroid/ChessTrack/src/uy/edu/fing/chesstrack/ChessTrackActivity.java @@ -8,7 +8,7 @@ import org.opencv.android.LoaderCallbackInterface; import org.opencv.android.OpenCVLoader; import org.opencv.core.Mat; -import uy.edu.chesstrack.communication.Server; +import uy.edu.chesstrack.communication.Client; import uy.edu.fing.chesstrack.modulovision.Adquisicion; import uy.edu.fing.chesstrack.modulovision.Calibracion; import android.app.Activity; @@ -18,17 +18,13 @@ import android.media.AudioManager; import android.media.ToneGenerator; import android.os.Bundle; import android.text.Editable; -import android.text.method.KeyListener; import android.util.Log; -import android.view.KeyEvent; import android.view.SurfaceView; import android.view.View; import android.view.View.OnClickListener; import android.view.WindowManager; import android.widget.Button; import android.widget.EditText; -import android.widget.TextView; -import android.widget.Toast; public class ChessTrackActivity extends Activity implements CvCameraViewListener { @@ -39,8 +35,7 @@ public class ChessTrackActivity extends Activity implements CvCameraViewListener private Adquisicion adq; private Calibracion calibrar; private Button btnCalibrar; - private Server ServidorCommunication; - private EditText text; + private Client ClientCommunication; //TODO es chancho pero ver luego private Mat frame; @@ -89,11 +84,10 @@ public class ChessTrackActivity extends Activity implements CvCameraViewListener // TODO Auto-generated catch block e.printStackTrace(); } - - getIp(); + getServerIp(); } - public void getIp(){ + public void getServerIp(){ AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Communication Setup"); alert.setMessage("Set server ip"); @@ -106,15 +100,17 @@ public class ChessTrackActivity extends Activity implements CvCameraViewListener public void onClick(DialogInterface dialog, int whichButton) { Editable value = input.getText(); Log.i(TAG,"INPUT=" + value.toString()); - ServidorCommunication = new Server(value.toString()); + ClientCommunication = new Client(value.toString()); } }); + /* alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { - // no server communication + // no server communication -- FIXME do not send info to client } }); + */ alert.show(); } @@ -166,7 +162,7 @@ public class ChessTrackActivity extends Activity implements CvCameraViewListener if (mOpenCvCameraView != null) { mOpenCvCameraView.disableView(); } - this.ServidorCommunication.Stop(); + this.ClientCommunication.Stop(); } @Override