if (buttonText == null) break;
  public void run()  {    while (!terminating) {      long connectStart = System.currentTimeMillis();      try {          s = new Socket(host, port);          try {              r = new BufferedReader(new InputStreamReader(s.getInputStream()));              try {                  notifyConnectStatusChanged(true);                  while (true) {                      String buttonText = r.readLine();                      int space1 = buttonText.indexOf(' ');                      if (space1 >= 0) {                          int space2 = buttonText.indexOf(' ', space1+1);                          String repeatCountStr = buttonText.substring(space1+1, space2);                          String idStr = buttonText.substring(space2+1);                          Button button = new Button(idStr, Integer.parseInt(repeatCountStr));                          notifyButtonPressed(button);                      }                  }              }              finally {                  notifyConnectStatusChanged(false);                  try {r.close();} catch (IOException e) {}              }          }          finally {              try {s.close();} catch (IOException e) {}          }      }      catch (NumberFormatException e) {          e.printStackTrace();      }      catch (IOException e) {          System.err.println("Failed to connect to lirc remote control at "+host+":"+port+": "+e.toString());      }      if (terminating)          break;        // If the failed connection took less than 20 seconds, then wait the remainder        // of the 20 seconds.  This protects against getting stuck in a tight loop.       long duration = System.currentTimeMillis() - connectStart;      if (duration < 20000L && duration >= 0L) {          try {              synchronized (timer) {                  timer.wait(20000L - duration);              }          }          catch (InterruptedException e) {}      }    }  }