title: How to check server connection is available or not in android
body: <p>Testing of Network Connection can be done by following method:</p>
  
  <pre><code> public boolean isNetworkAvailable() 
  {
      ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo networkInfo = cm.getActiveNetworkInfo();
  
      if (networkInfo != null &amp;&amp; networkInfo.isConnected())
      {
          return true;
      }
      return false;
  }
  </code></pre>
  
  <p>But i don't know how to check the server connection.I had followed this method</p>
  
  <pre><code>public boolean isConnectedToServer(String url, long timeout) {
  try{
      URL myUrl = new URL(url);
      URLConnection connection = myUrl.openConnection();
      connection.setConnectTimetout(timeout);
      connection.connect();
      return true;
  } catch (Exception e) {
      // Handle your exceptions
      return false;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>it doesn't works....Any Ideas Guys!!</p>