Read from unix socket file

643 Views Asked by At

I'm trying to read some lines (or just something) from /var/run/docker.sock. Basically I'm trying to convert the following into code.

curl --unix-socket /var/run/docker.sock http://localhost/events

I'm using the jnr.unixsocket library and my code is as follows

val socketAddress = UnixSocketAddress(File("/var/run/docker.sock"))
val socket = UnixSocketChannel.open(socketAddress).socket()
val inputStream = socket.inputStream
val reader = inputStream.bufferedReader()
while (true) {
    val line = reader.readLine()
    println(line)
}

Where do I "put" the http://localhost/events ? The above code just blocks on reader.readLine(). Any suggestion about how to read events? Please note that I'm not forced to use JNR. It just seemed like the best option but I'm open to alternatives.

0

There are 0 best solutions below