Skip to content
Snippets Groups Projects
Commit ba4d9483 authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

Fix by C.Keller

parent 4bfc42e8
No related branches found
No related tags found
No related merge requests found
...@@ -71,8 +71,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -71,8 +71,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
// On réserve les espaces pour les commandes // On réserve les espaces pour les commandes
boutons.forEach((btn) -> numCommands.add(idIndexes.indexOf(btn.getId()), 0)); boutons.forEach((btn) -> numCommands.add(idIndexes.indexOf(btn.getId()), 0));
} }
tacheDeFond = new backTasks();
tacheDeFond.execute();
} }
@Override @Override
...@@ -87,8 +85,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -87,8 +85,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
numCommands.set(idIndexes.indexOf(v.getId()), numCommands.get(idIndexes.indexOf(v.getId()))+1); numCommands.set(idIndexes.indexOf(v.getId()), numCommands.get(idIndexes.indexOf(v.getId()))+1);
setButtonText(bouton); setButtonText(bouton);
String message = numTable+nomBoutons.get(idIndexes.indexOf(v.getId()));
tacheDeFond = new backTasks();
tacheDeFond.execute(message);
// Envoie de la commande // Envoie de la commande
tacheDeFond.registerCommand(numTable+nomBoutons.get(idIndexes.indexOf(v.getId()))); //tacheDeFond.registerCommand(numTable+nomBoutons.get(idIndexes.indexOf(v.getId())));
}catch ( Exception e ){ }catch ( Exception e ){
Log.e("Erreur", e.getMessage()); Log.e("Erreur", e.getMessage());
} }
......
...@@ -9,31 +9,35 @@ import java.io.PrintWriter; ...@@ -9,31 +9,35 @@ import java.io.PrintWriter;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
public class backTasks extends AsyncTask { public class backTasks extends AsyncTask<String, Void, Void> {
private Socket socket; private Socket socket;
private PrintWriter output; private PrintWriter output;
private BufferedReader input; private BufferedReader input;
@Override @Override
protected Object doInBackground(Object[] objects) { protected Void doInBackground(String... message) {
int serverPort = 9874; int serverPort = 9874;
String address = "chadok.info"; String address = "chadok.info";
try { try {
InetAddress ipAddress = InetAddress.getByName(address); //InetAddress ipAddress = InetAddress.getByName(address);
Log.i("backTasks:", "Connecting to " + address + ":"+ serverPort + "..."); Log.i("backTasks:", "Connecting to " + address + ":"+ serverPort + "...");
socket = new Socket(ipAddress, serverPort); socket = new Socket(address, serverPort);
Log.i("backTasks:", "Connected"); Log.i("backTasks:", "Connected");
output = new PrintWriter(socket.getOutputStream(), true); output = new PrintWriter(socket.getOutputStream(), true);
input = new BufferedReader(new InputStreamReader(socket.getInputStream())); input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
registerCommand(message[0]);
/*
while(true){ while(true){
String message = input.readLine(); String message = input.readLine();
if (message != null){ if (message != null){
Log.i("backTasks", "received message: " + message); Log.i("backTasks", "received message: " + message);
} }
} }
*/
} catch (Exception x) { } catch (Exception x) {
x.printStackTrace(); x.printStackTrace();
...@@ -45,6 +49,7 @@ public class backTasks extends AsyncTask { ...@@ -45,6 +49,7 @@ public class backTasks extends AsyncTask {
if(output != null){ if(output != null){
Log.i("backTasks", "registered command: "+command); Log.i("backTasks", "registered command: "+command);
output.write(command); output.write(command);
output.flush();
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment