title: Checking if server is online from Java code
body: <p>I want to check if server application is available. After server is started I want to stop checking until the server changes status. How to do that with my code:</p>
  
  <pre><code> private static final String SERVER_ADDRESS = "192.144.10.10";
      private static final int TCP_SERVER_PORT = 8890;
      private static boolean connected = false;
      static Socket s;
  
      public static void main(String[] args) {
  
      Timer timer = new Timer();
      timer.schedule(task, 01, 5001); }  
  
  static TimerTask task = new TimerTask() {
  
          @Override
          public void run() {
              // TODO Auto-generated method stub
              if (connected == false)
              {
              System.out.println(hostAvailabilityCheck());
              }
          }
      };
  
      public static boolean hostAvailabilityCheck()
      { 
  
          boolean available = true; 
          try {               
              if (connected == false)
              { (s = new Socket(SERVER_ADDRESS, TCP_SERVER_PORT)).close();    
              }               
              } 
          catch (UnknownHostException e) 
              { // unknown host 
              available = false;
              s = null;
              } 
          catch (IOException e) { // io exception, service probably not running 
              available = false;
              s = null;
              } 
          catch (NullPointerException e) {
              available = false;
              s=null;
          }
  
  
          return available;   
      } 
  </code></pre>
  
  <p>Is there any better way to solve this?</p>