检查IP和端口在超时时间内是否可以连接
/** * 检查IP和端口是否可以连接 * @param ip * @param port * @return */ private static boolean testConnect(String ip,int port) { Boolean isConnect = false; Socket connect = new Socket(); try { InetSocketAddress inetSocketAddress = new InetSocketAddress(ip, port); connect.connect(inetSocketAddress, 1500); isConnect = connect.isConnected(); } catch (IOException e) { }finally { if (connect != null) { try { connect.close(); } catch (IOException e) { } } } return isConnect; }
原文地址:https://www.cnblogs.com/lijianda/p/10840449.html
时间: 2024-10-13 20:49:32