KtorSocketClient

class KtorSocketClient : Closeable

Client class for managing the connection to the PGN daemon.

This is the class responsible for managing the underlying socket connections, and sending raw byte data back and forth over the socket.

It is a generic socket class, and does not contain any logic which is specific to PGN.

If you are implementing this class, chances are that you want the PicoGpioNetClient class instead.

Example usage:

val response = KtorSocketClient().use{ client ->
client.connect(ip, port)
client.write(someBytes, flush=true)
client.read(expectedResponseLength)
}

See also

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard
suspend fun connect(ipAddress: String, port: Int)

Attempts to establish a connection to the PGN daemon.

Link copied to clipboard
suspend fun flush(timeout: Long)

Flushes the write channel.

Link copied to clipboard
suspend fun read(length: Int, timeout: Long): ByteArray

Receives the specified number of bytes from the read channel.

Link copied to clipboard
suspend fun write(bytes: ByteArray, flush: Boolean = false, timeout: Long)

Sends data to the PGN daemon.