static int isPortOpen_timeout = 500; static boolean isPortOpen(int port) { try { Socket socket = new Socket(); socket.connect(new InetSocketAddress("127.0.0.1", port), isPortOpen_timeout); //print("Connected to " + ip + ":" + port); socket.close(); return true; } catch (Exception ex) { return false; } }