Java HTTP Port Find isLivereloadAvailable(int port)

Here you can find the source of isLivereloadAvailable(int port)

Description

is Livereload Available

License

Open Source License

Declaration

public static boolean isLivereloadAvailable(int port) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015 Red Hat, Inc./*w  w w  . j a  v a 2  s . c  o m*/
 * Distributed under license by Red Hat, Inc. All rights reserved.
 * This program is made available under the terms of the
 * Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributor:
 *     Red Hat, Inc. - initial API and implementation
 ******************************************************************************/

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    public static boolean isLivereloadAvailable(int port) {
        try {
            HttpURLConnection.setFollowRedirects(false);
            URL url = new URL("http://localhost:" + port + "/livereload.js"); //$NON-NLS-1$ //$NON-NLS-2$
            HttpURLConnection con = (HttpURLConnection) url
                    .openConnection();
            con.setConnectTimeout(1000);
            con.setRequestMethod("HEAD"); //$NON-NLS-1$
            return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
        } catch (IOException e) {
            return false;
        }
    }
}

Related

  1. isFreePort(int portNumber)
  2. isFreeTCPPort(final int port)
  3. isHostAvailable(final String host, final int port)
  4. isHostReachable(String host, int port, int connTimeout)
  5. isListening(String host, int port)
  6. isLocalPortAvailable(final int port)
  7. isLocalPortFree(final int port)
  8. isLocalPortOccupied(int portNum)
  9. isLocalPortUsed(int port)