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
| 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;
IdentificationActivity ident = (IdentificationActivity)ThreadAppelant;
do {
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");
if(ThreadAppelant instanceof IdentificationActivity)
{
reponse = rd.readLine();
ident.setReponseConnection(reponse);
if(reponse == null || "".equals(reponse)) {
ident.setReponseLue(false);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Erreur identification");
builder.setTitle("Erreur");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
ClientThread.this.finish();
}
});
AlertDialog alert = builder.create();
alert.show();
}
else {
ident.setReponseLue(true);
}
synchronized(ThreadAppelant) {
ThreadAppelant.notify();
}
}
}
catch(Exception e) {
Log.e("IdentificationActivity", "S: Error", e);
}
}
}while(ident.getReponseConnection().equals(""));
socket.close();
Log.d("IdentificationAcitivty", "C: Closed");
}
catch(Exception e) {
Log.e("IdentificationActivity", "C: Error", e);
connected = false;
}
} |
Partager