@Test public void testIsPortUsing() throws IOException { int port = AvailablePortFinder.getNextAvailable(); boolean isUsing = NetUtil.isPortUsing("127.0.0.1", port); Assert.assertFalse(isUsing); port = 6666; ServerSocket ss = new ServerSocket(port); isUsing = NetUtil.isPortUsing("127.0.0.1", port); Assert.assertTrue(isUsing); ss.close(); System.out.println(String.format("[CRAFT-ATOM-UTIL] (^_^) <%s> Case -> test is port using. ", CaseCounter.incr(2))); }
public static boolean isPortUsing(String host, int port) { try { new Socket(host, port); return true; } catch (IOException e) { return false; } }
NetUtil { public static boolean isPortUsing(String host, int port) { try { new Socket(host, port); return true; } catch (IOException e) { return false; } } }
NetUtil { public static boolean isPortUsing(String host, int port) { try { new Socket(host, port); return true; } catch (IOException e) { return false; } } private  NetUtil(); }
NetUtil { public static boolean isPortUsing(String host, int port) { try { new Socket(host, port); return true; } catch (IOException e) { return false; } } private  NetUtil(); static InetAddress getIpv4Address(); static InetAddress getIpv4Address(String prefix); static boolean isLocalPortUsing(int port); static boolean isPortUsing(String host, int port); }
NetUtil { public static boolean isPortUsing(String host, int port) { try { new Socket(host, port); return true; } catch (IOException e) { return false; } } private  NetUtil(); static InetAddress getIpv4Address(); static InetAddress getIpv4Address(String prefix); static boolean isLocalPortUsing(int port); static boolean isPortUsing(String host, int port);  }