NetworkRuntime

The socket runtime. One SelectorManager drives all non-blocking I/O, the way a single Boost.Asio io_context does in libtorrent. ktor-network's selector is coroutine-native, so there are no callbacks: a read simply suspends.

Constructors

Link copied to clipboard
constructor(context: CoroutineContext)

Properties

Link copied to clipboard

When set, all outbound TCP connectTcp dials are tunnelled through this proxy (SOCKS5/HTTP).

Link copied to clipboard
val selector: SelectorManager

Functions

Link copied to clipboard
suspend fun NetworkRuntime.bindTcp(port: Int, host: String = "0.0.0.0"): TcpServer

Bind a listening TCP socket on host:port (port 0 = an ephemeral free port).

Link copied to clipboard
suspend fun NetworkRuntime.bindUdp(port: Int = 0, host: String = "0.0.0.0"): UdpSocket

Bind a UDP socket on host:port (port 0 = any free port). host defaults to the IPv4 wildcard 0.0.0.0; pass "::" to bind the IPv6 (dual-stack on most OSes) wildcard, the way libtorrent's udp_socket::bind honours the listen interface's address family.

Link copied to clipboard
fun close()
Link copied to clipboard
suspend fun NetworkRuntime.connectTcp(host: String, port: Int, connectTimeoutMs: Long = 0, bypassProxy: Boolean = false): TcpConnection

Open a TCP connection to host:port, tunnelling through NetworkRuntime.proxy if set.