Java HTTP Port Find canConnectOn(String host, int port)

Here you can find the source of canConnectOn(String host, int port)

Description

can Connect On

License

Open Source License

Declaration

public static boolean canConnectOn(String host, int port) 

Method Source Code

//package com.java2s;
/*/* w w  w. ja va2  s .  c o m*/
 * Based on "InstallCert.java" 1.1 06/10/09
 *
 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 * Use is subject to license terms.
 * 
 * It's not known what the "license" above is, but the code came from here:
 * http://blogs.sun.com/andreas/entry/no_more_unable_to_find
 * 
 * Call initSsl to initialize SSL on the port you know that JavaMail is
 * about to use before you call JavaMail. There may be a cleaner way, but
 * I haven't found it.
 * 
 * This was hard enough!
 */

import java.net.*;

public class Main {
    public static boolean canConnectOn(String host, int port) {
        // FIXME: change this class to NetworkUtilities, or move this into the account configuration code (when we have some)?
        try {
            Socket socket = new Socket(host, port);
            socket.close();
            return true;
        } catch (Exception ex) {
            return false;
        }
    }
}

Related

  1. availablePort(int port)
  2. availablePort(int pPort)
  3. availablePort(int prefered)
  4. canConnect(String host, int port)
  5. canConnect(String host, int port)
  6. createUnresolved(String host, int port)
  7. doSend(String command, String server, String port)
  8. executeHttpCommand(String host, int port, String request, String charset)
  9. exportResource(Class fromClass, String resourceName, String exportPath)