1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| public class IdentificationActivity extends Activity implements OnClickListener {
Button buttonValider = null;
EditText editNom;
EditText editPass;
private String nom;
private String pass;
private String reponseConnection;
private boolean connected = false;
private boolean reponseLue = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.identification);
editNom = (EditText)findViewById(R.id.editTextNom);
editPass = (EditText)findViewById(R.id.editTextPass);
buttonValider = (Button)findViewById(R.id.buttonValidIdent);
buttonValider.setOnClickListener(this);
}
@Override
synchronized public void onClick(View v) { // click sur le bouton valider de l'ihm de creation
// TODO Auto-generated method stub
if(v == buttonValider) {
nom = editNom.getText().toString();
pass = editPass.getText().toString();
Thread cThread = new Thread(new ClientThread());
cThread.start();
while(reponseLue == false) {
try {
wait();
}
catch(InterruptedException ie) {
ie.printStackTrace();
}
}
if(reponseConnection.equals("OK")) {
Intent monIntent = new Intent(this, ConfigurationActivity.class);
startActivity(monIntent);
}
}
}
public class ClientThread implements Runnable {
@Override
synchronized public void run() {
// TODO Auto-generated method stub
try {
Log.d("IdentificationActivity", "C: Connecting...");
Socket socket = new Socket("192.168.58.22", 1234);
connected = true;
if(connected) {
try {
Log.d("IdentificationAcitivity", "C: Sending Command");
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out.println("IDENT,"+nom+","+pass);
out.flush();
Log.d("IdentificationActivity", "C: Sent");
reponseConnection = rd.readLine();
reponseLue = true;
notify();
}
catch(Exception e) {
Log.e("IdentificationActivity", "S: Error", e);
}
}
socket.close();
Log.d("IdentificationAcitivty", "C: Closed");
}
catch(Exception e) {
Log.e("IdentificationActivity", "C: Error", e);
connected = false;
}
}
}
} |
Partager