query

abstract fun query(host: String, port: Int, request: String, timeoutMs: Int): String(source)

Connects to a TCP service, writes the request and reads until EOF.

Loopback needs network; a remote host also needs network.outbound. The request is at most 2048 UTF-8 bytes; a newline is appended. The response is at most {@value #MAX_RESPONSE_BYTES} bytes and the timeout is capped at {@value #MAX_TIMEOUT_MS} ms, including DNS resolution. The read runs to EOF, so a server that keeps the connection open after sending 8 KiB yields a java.net.SocketTimeoutException rather than a truncated result.

Return

the response text

Since

api 2

Parameters

host

a loopback name, a host name or an IP address

port

the port, 1–65535

request

the request, or null for none

timeoutMs

the timeout; capped at {@value #MAX_TIMEOUT_MS}

Throws

on connect, write, resolve, read or request-size failure

if the required permission is not granted