Socket socket; try { socket = new Socket(trackDatabase.getHost(), trackDatabase.getPort()); } catch (UnknownHostException uhe) { uhe.printStackTrace();   socket = new Socket("202.72.160.235", trackDatabase.getPort()); }
Socket socket = new Socket(trackDatabase.getHost(), trackDatabase.getPort());
  public void contactServer(TrackDatabase trackDatabase) {    try {      setState(getResourceString("DownloadThread.Connecting_to_server")); //$NON-NLS-1$      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()); //$NON-NLS-1$      }      InputStream is = socket.getInputStream();      setState(getResourceString("DownloadThread.Sending_server_request")); //$NON-NLS-1$      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()); //$NON-NLS-1$ //$NON-NLS-2$      GZIPOutputStream gos = new GZIPOutputStream(os);      gos.write(buf);      gos.finish();      os.flush();      setState(getResourceString("DownloadThread.Receiving_server_reply")); //$NON-NLS-1$      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); //$NON-NLS-1$      if (errorCode.length() != 0)        handleError(errorCode, reply.getErrorURLString());      else//if no error incrmement serial        trackDatabase.incrementSerial();    }    catch (UnknownHostException uhe) {      handleError("nohost", "hostnotfound.html"); //$NON-NLS-1$ //$NON-NLS-2$    }    catch (ConnectException ce) {      if (ce.getMessage().equals("Connection timed out")) //$NON-NLS-1$        handleError("conntimeout", "connectiontimeout.html"); //$NON-NLS-1$ //$NON-NLS-2$      else if (ce.getMessage().equals("Connection refused")) //$NON-NLS-1$        handleError("connrefused", "connectionrefused.html"); //$NON-NLS-1$ //$NON-NLS-2$      else        handleError("conntimeout", "connectionfailed.html"); //$NON-NLS-1$ //$NON-NLS-2$    }    catch (IOException e) {      e.printStackTrace();    }  }