static int quickPortCheck_timeout = 5000; // returns hello message or null static S quickPortCheck(int port) { try { Socket socket = new Socket(); try { socket.setSoTimeout(quickPortCheck_timeout); socket.connect(new InetSocketAddress("localhost", port), quickPortCheck_timeout); //if (verbose) print("Connected to " + ip + ":" + port); BufferedReader in = new BufferedReader( new InputStreamReader(socket.getInputStream(), "UTF-8")); ret or(in.readLine(), "?"); } finally { socket.close(); } } catch (Exception ex) { return null; } }