title: JAVA Specifying port with InetAddress
body: <p>I am using InetAddress to determine if my server is online.</p>
  
  <p>If the server is offline it will restart the server.</p>
  
  <p>This process loops every 5 minutes to check once again if the server is online.</p>
  
  <p>It works fine but now I need to figure out how to specify that I want to use port 43594 when checking the server status instead of the default port 80.</p>
  
  <p>Thanks! Here's my code:</p>
  
  <pre><code>import java.net.InetAddress;
  public class Test extends Thread {
      public static void main(String args[]) {
          try {
              while (true) {
                  try
                  {
                      InetAddress address = InetAddress.getByName("cloudnine1999.no-ip.org");
                      boolean reachable = address.isReachable(10000);
                      if(reachable){
                          System.out.println("Online");
                      }
                      else{
                          System.out.println("Offline: Restarting Server...");
                          Runtime.getRuntime().exec("cmd /c start start.bat");
                      }
                  }
                  catch (Exception e)
                  {
                      e.printStackTrace();
                  }
                  Thread.sleep(5 * 60 * 1000);
              }
          }
          catch (InterruptedException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>Okay so I took someones advice and I made it into this. But now when I uncomment this line..
  <code>Runtime.getRuntime().exec("cmd /c start start.bat");</code></p>
  
  <p>I get this error..</p>
  
  <p><code>error: unreported exception IOException; must be caught or declared to be thrown</code></p>
  
  <p>This is my current code:</p>
  
  <pre><code>import java.net.*;
  import java.io.*;
  public class Test extends Thread {
      public static void main(String args[]) {
          try {
              while (true) {
                  SocketAddress sockaddr = new InetSocketAddress("cloudnine1999.no-ip.org", 43594);
                  Socket socket = new Socket();
                  boolean online = true;
                  try {
                      socket.connect(sockaddr, 10000);
                  }
                  catch (IOException IOException) {
                      online = false;
          }
                  if(!online){
              System.out.println("OFFLINE: Restarting Server..");
              //Runtime.getRuntime().exec("cmd /c start start.bat");
          }
                  if(online){
                      System.out.println("ONLINE");
                  }
                  Thread.sleep(1 * 10000);
              }
          }
          catch (InterruptedException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>