response.setName("irate-client");
response.setName("IrateClient");
  public void makeContact(InputStream in, OutputStream out) {    boolean notFinished = true;    boolean fatal = false;    try {      while (notFinished) {        XMLElement command = new XMLElement(new Hashtable(), true, false);        XMLElement response = new XMLElement(new Hashtable(), true, false);        response.setName("irate-client");        try {          command.parseFromReader(new InputStreamReader(in));        } catch (XMLParseException e) {          fatal = true;        }        boolean replyNeeded = false;        if (fatal || !command.getName().equals("command")) {          // Fatal error - compose response, disconnect.          response.setAttribute("type", "error");          response.setAttribute("errorcondition", "unknown-command");          response.setIntAttribute("fatal",1);          notFinished = false;          replyNeeded = true;        } else {          // Check commands          String cmdType = command.getStringAttribute("type");          if (cmdType.equals("currenttrack")) {            trackResponseXML(response, app.getPlayingTrack());            response.setAttribute("source","playing");            replyNeeded = true;          } else if (cmdType.equals("playerstate")) {            response.setIntAttribute("playerstate", app.isPaused()?0:1);            replyNeeded = true;          } else if (cmdType.equals("selected")) {            trackResponseXML(response, app.getSelectedTrack());            response.setAttribute("source","selected");            replyNeeded = true;          } else if (cmdType.equals("invert-pause")) {            app.setPaused(!app.isPaused());                      } else if (cmdType.equals("pause")) {            app.setPaused(true);                      } else if (cmdType.equals("unpause")) {            app.setPaused(false);          } else if (cmdType.equals("skip")) {            app.skip();            trackResponseXML(response, app.getPlayingTrack());            response.setAttribute("source","playing");            replyNeeded = true;                    } else if (cmdType.equals("rateplaying")) {            int rating = command.getIntAttribute("rate");            app.setRating(app.getPlayingTrack(), rating);            trackResponseXML(response, app.getSelectedTrack());            response.setAttribute("source","playing");            replyNeeded = true;          } else if (cmdType.equals("rateselected")) {            int rating = command.getIntAttribute("rate");            app.setRating(app.getSelectedTrack(), rating);            trackResponseXML(response, app.getSelectedTrack());            response.setAttribute("source","selected");            replyNeeded = true;          } else if (cmdType.equals("disconnect")) {            notFinished = false;          } else { // finally, nothing matched.            response.setAttribute("type", "error");            response.setAttribute("errorcondition", "unknown-command");            response.setIntAttribute("fatal",0);            replyNeeded = true;          }        }        if (replyNeeded) {          OutputStreamWriter outSW = new OutputStreamWriter(out);          response.write(outSW);          outSW.write('\n');          outSW.flush(); // If we don't flush, it doesn't get sent.          outSW = null; // Just to avoid them hanging around unwanted.        }      }    } catch (IOException e) {}    try {      in.close();      out.close();    } catch (IOException e) {}  } // makeContact(InputStream in, OutputStream out)