Check if the server is reachable

@param baseUrl The url of the server to test
@param connectTimeout connection timeout
@param timeUnit connection timeout unit
@return true if reachable otherwise false.
@throws IOException if an error occurs
11842
public static boolean isServerReachable(String baseUrl, long connectTimeout, TimeUnit timeUnit) throws IOException {
        OkHttpClient client = new OkHttpClient();
        client.setConnectTimeout(connectTimeout, timeUnit);
        return isServerReachable(baseUrl, client);
    }
687421
public void setConnectionTimeout(long connectionTimeout, TimeUnit timeUnit) {
		this.connectionTimeoutInMs = TimeUnit.MILLISECONDS.convert(connectionTimeout, timeUnit);
	}
555921
private static boolean waitForServerUp(String hostname, int port, long timeout) {
    long start = System.currentTimeMillis();
    while (true) {
      try {
        Socket sock = new Socket(hostname, port);
        BufferedReader reader = null;
        try {
          OutputStream outstream = sock.getOutputStream();
          outstream.write("stat".getBytes());
          outstream.flush();

          Reader isr = new InputStreamReader(sock.getInputStream());
          reader = new BufferedReader(isr);
          String line = reader.readLine();
          if (line != null && line.startsWith("Zookeeper version:")) {
            return true;
          }
        } finally {
          sock.close();
          if (reader != null) {
            reader.close();
          }
        }
      } catch (IOException e) {
        // ignore as this is expected
        logger.info("server " + hostname + ":" + port + " not up " + e);
      }

      if (System.currentTimeMillis() > start + timeout) {
        break;
      }
      try {
        Thread.sleep(250);
      } catch (InterruptedException e) {
        // ignore
      }
    }
    return false;
  }
175570
protected boolean isAvailable(URL url) {

        try (InputStream inputStream = url.openStream()) {
            return true;
        } catch (IOException e) { //NOSONAR
            LOG.debug("URL {} not available", url, e);
            return false;
        }
    }
1299633
public static boolean canTelnet(String ip, int port, int timeout) {
        Socket socket = null;
        try {
            socket = new Socket();
            socket.connect(new InetSocketAddress(ip, port), timeout);
            return socket.isConnected() && !socket.isClosed();
        } catch (Exception e) {
            return false;
        } finally {
            IOUtils.closeQuietly(socket);
        }
    }
1255766
@Override
	public void setConnectionTimeoutMS(int connectionTimeoutMS) {
    	connectionManager.getParams().setConnectionTimeout(connectionTimeoutMS);
    	http.getParams().setConnectionManagerTimeout(connectionTimeoutMS);
	}
1117816
@Override
    public boolean validateObject(HostAndPort hostAndPort, PooledObject<SocketOutputStream> socketOutputStreamRef) {
        Socket socket = socketOutputStreamRef.getObject().getSocket();
        return socket.isConnected()
                && socket.isBound()
                && !socket.isClosed()
                && !socket.isInputShutdown()
                && !socket.isOutputShutdown();
    }
1038113
def _can_connect(self):
        """"""
        self.log('Trying to reach configured connectivity check endpoint', lvl=verbose)

        try:
            socket.setdefaulttimeout(self.config.timeout)
            socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((self.config.host, self.config.port))
            return True
        except Exception as ex:
            self.log(ex, pretty=True, lvl=debug)
            return False
882771
public final HttpClient baseUrl(String baseUrl) {
		Objects.requireNonNull(baseUrl, "baseUrl");
		return tcpConfiguration(tcp -> tcp.bootstrap(b -> HttpClientConfiguration.baseUrl(b, baseUrl)));
	}
107042
public static ApiVersion getMythVersion(String baseUri, long connectTimeout, TimeUnit timeUnit) throws IOException {
        OkHttpClient client = new OkHttpClient();
        client.setConnectTimeout(connectTimeout, timeUnit);
        return getMythVersion(baseUri, client);
    }
449348
private InputStream connect(String url) throws IOException {
		URLConnection conn = new URL(URL_BASE + url).openConnection();
		conn.setConnectTimeout(CONNECT_TIMEOUT);
		conn.setReadTimeout(READ_TIMEOUT);
		conn.setRequestProperty("User-Agent", USER_AGENT);
		return conn.getInputStream();
	}
602992
protected boolean _connect(long timeout) {
    log.debug("Attempting connection...");
    ConnectFuture connFuture = this.connector.connect(new InetSocketAddress(
        this.host, this.port));
    if (!connFuture.awaitUninterruptibly(timeout)) {
      log.warn("Unable to connect to world model after {}ms.",
          Long.valueOf(this.connectionTimeout));
      return false;
    }
    if (!connFuture.isConnected()) {
      log.debug("Failed to connect.");
      return false;
    }

    try {
      log.debug("Attempting connection to {}:{}.", this.host,
          Integer.valueOf(this.port));
      this.session = connFuture.getSession();
    } catch (RuntimeIoException ioe) {
      log.error(String.format(
          "Could not create session to World Model (C) %s:%d.", this.host,
          Integer.valueOf(this.port)), ioe);
      return false;
    }
    return true;
  }
915999
protected boolean isConnected(final String host, final int port, final int timeoutInMs,
      final ErrorHandler errorHandler) {
    final Socket socket = new Socket();
    return isConnected(socket, host, port, timeoutInMs, errorHandler);
  }
166800
def connection_ok():
    
    try:
        urlopen(Dataset.base_url, timeout=1)
        # if an index page is ever added, this will pass through
        return True
    except HTTPError:
        # There's no index for BASE_URL so Error 404 is expected
        return True
    except URLError:
        # This is raised if there is no internet connection
        return False
678960
@Override
    synchronized public boolean connect(InetSocketAddress addr){
        long now = System.currentTimeMillis();
        if(isStarted){
            return true;
        }
        isStarted = true;

        String host = addr.getHostName();
        int port = addr.getPort();

        serverURI = URI.create("ws://" + host + ":" + port + "/ws/service/");

        if(LOGGER.isTraceEnabled()){
            LOGGER.trace("WebSocket connect to timeOut=" + connectTimeOut + " - " + serverURI.toString());
        }

        client = new WebSocketClient();

        doConnect();

        synchronized(sessionLock){
            long to = connectTimeOut - (System.currentTimeMillis() - now);
            while(! connected && to > 0){

                try {
                    sessionLock.wait(to);
                } catch (InterruptedException e) {
                    // do nothing.
                }
                to = connectTimeOut - (System.currentTimeMillis() - now);
            }
        }
        return true;
    }
1005964
public URLConnection createURLConnection(URL url) throws IOException {
        URLConnection conn = url.openConnection();
		return conn;
	}
624951
private static HttpURLConnection openURLConnection(URL url) throws IOException {
		// This method should be moved to a utility class in BioJava 5.0

		final int timeout = 5000;
		final String useragent = "BioJava";

		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		conn.setRequestProperty("User-Agent", useragent);
		conn.setInstanceFollowRedirects(true);
		conn.setConnectTimeout(timeout);
		conn.setReadTimeout(timeout);

		int status = conn.getResponseCode();
		while (status == HttpURLConnection.HTTP_MOVED_TEMP
				|| status == HttpURLConnection.HTTP_MOVED_PERM
				|| status == HttpURLConnection.HTTP_SEE_OTHER) {
			// Redirect!
			String newUrl = conn.getHeaderField("Location");

			if(newUrl.equals(url.toString())) {
				throw new IOException("Cyclic redirect detected at "+newUrl);
			}

			// Preserve cookies
			String cookies = conn.getHeaderField("Set-Cookie");

			// open the new connection again
			url = new URL(newUrl);
			conn.disconnect();
			conn = (HttpURLConnection) url.openConnection();
			if(cookies != null) {
				conn.setRequestProperty("Cookie", cookies);
			}
			conn.addRequestProperty("User-Agent", useragent);
			conn.setInstanceFollowRedirects(true);
			conn.setConnectTimeout(timeout);
			conn.setReadTimeout(timeout);
			conn.connect();

			status = conn.getResponseCode();

			logger.info("Redirecting from {} to {}", url, newUrl);
		}
		conn.connect();

		return conn;
	}