Here you can find the source of canConnectOn(String host, int port)
public static boolean canConnectOn(String host, int port)
//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; } } }