List of utility methods to do HTTP Port Find
boolean | ping(String domain, int port) ping boolean result = false; Socket socket = null; try { socket = new Socket(domain, port); result = true; } catch (UnknownHostException e) { } catch (IOException e) { } finally { ... |
Boolean | pingServer(String host, Integer port) ping Server String timeStamp = ""; Socket socket = null; BufferedReader br = null; try { socket = new Socket(host, port); br = new BufferedReader(new InputStreamReader(socket.getInputStream())); timeStamp = br.readLine(); socket.close(); ... |
int | randomAvailablePort() random Available Port try { ServerSocket socket = new ServerSocket(0); int port = socket.getLocalPort(); socket.close(); return port; } catch (IOException e) { throw new RuntimeException(e); |
int | randomFreePort() Returns a random free port and marks that port as taken. int port = 0; boolean portAvailable = true; ; do { port = randomPort(); portAvailable = available(port); } while (!portAvailable); return port; ... |
int | randomFreePort() random Free Port int port = 0; do { port = randomPort(); try { ServerSocket sock = new ServerSocket(port); sock.close(); } catch (IOException ex) { port = 0; ... |
int | randomFreePort() Returns a random free port and marks that port as taken. int port = 0; do { port = randomPort(); if (takenRandomPorts.contains(port)) { port = 0; continue; takenRandomPorts.add(port); ... |
String | read(String host, int port) read return read(host, port, null);
|
List | readHttpContent(String domain, String resource, int port) read Http Content Socket socket = null; try { socket = new Socket(domain, port); PrintWriter out = new PrintWriter(socket.getOutputStream()); StringBuilder send = new StringBuilder(); send.append("GET " + resource + " HTTP/1.0").append("\n"); send.append("Accept: text/html").append("\n"); send.append("\n"); ... |
void | replace(final String host, final int port, final String user, final String program, final String relation, final String dataset, final String format) Replace the contents of a dataset. URL url = getDatasetUrl(host, port, user, program, relation, format); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestProperty("Content-Type", "application/octet-stream"); conn.setRequestMethod("PUT"); byte[] payload = dataset.getBytes("UTF-8"); conn.setFixedLengthStreamingMode(payload.length); try { ... |
InetSocketAddress | resolve(final String desc, final int defaultPort) Parse and resolve an address string, looking up the IP address. final InetSocketAddress addr = parse(desc, defaultPort); if (addr.getAddress() != null && addr.getAddress().isAnyLocalAddress()) { return addr; try { final InetAddress host = InetAddress.getByName(addr.getHostName()); return new InetSocketAddress(host, addr.getPort()); } catch (UnknownHostException e) { ... |