System.out.println("reply: "); System.out.println(reply.toString());
  public void contactServer(TrackDatabase trackDatabase) {    try {      setState("Connecting to server");      Socket socket;      try {        socket = new Socket(trackDatabase.getHost(), trackDatabase.getPort());      }      catch (UnknownHostException uhe) {        uhe.printStackTrace();          // Retrying using the IP address        socket = new Socket("202.72.160.235", trackDatabase.getPort());      }      InputStream is = socket.getInputStream();      setState("Sending server request");      OutputStream os = socket.getOutputStream();      String str;            if(contactCount++ > 0)        str = trackDatabase.toSerialString();      //send full db on first connect      else        str = trackDatabase.toString();            System.out.println("Request:");      System.out.println(str);      byte[] buf = str.getBytes();      os.write(("Content-Length: " + Integer.toString(buf.length) + "\r\nContent-Encoding: gzip\r\n\r\n").getBytes());      GZIPOutputStream gos = new GZIPOutputStream(os);      gos.write(buf);      gos.finish();      os.flush();      setState("Receiving server reply");      TrackDatabase reply = new TrackDatabase(new GZIPInputStream(is));      is.close();      os.close();      System.out.println("reply: ");      System.out.println(reply.toString());      trackDatabase.add(reply);      trackDatabase.save();      String errorCode = reply.getErrorCode();//if errorCode == "password" we can give a better prompt.System.out.println("DownloadThread.java:326: " + errorCode);      if (errorCode.length() != 0)        handleError(errorCode, reply.getErrorURLString());      else//if no error incrmement serial        trackDatabase.incrementSerial();    }    catch (UnknownHostException uhe) {      handleError("nohost", "hostnotfound.html");    }    catch (ConnectException ce) {      if (ce.getMessage().equals("Connection timed out"))        handleError("conntimeout", "connectiontimeout.html");      else if (ce.getMessage().equals("Connection refused"))        handleError("connrefused", "connectionrefused.html");      else        handleError("conntimeout", "connectionfailed.html");    }    catch (IOException e) {      e.printStackTrace();    }  }