or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.mdio-operations.mdselector-management.mdsocket-addresses.mdsocket-configuration.mdsocket-creation.mdtcp-operations.mdudp-operations.md
tile.json

tessl/maven-io-ktor--ktor-network-tvosx64

Ktor network utilities - tvOS x64 target implementation of asynchronous TCP/UDP sockets and related networking functionality for the Ktor framework

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/io.ktor/ktor-network-tvosx64@3.2.x

To install, run

npx @tessl/cli install tessl/maven-io-ktor--ktor-network-tvosx64@3.2.0

index.mddocs/

Ktor Network - tvOS x64

Ktor Network provides asynchronous TCP and UDP socket operations for the tvOS x64 platform using Kotlin coroutines. This package enables developers to create network applications with socket-based communication, supporting both client and server scenarios. It includes features for connection management, socket lifecycle handling, and integration with Kotlin's coroutine-based concurrency model.

Package Information

  • Package Name: io.ktor:ktor-network-tvosx64
  • Package Type: maven
  • Language: Kotlin
  • Platform: tvOS x64 (Apple TV 64-bit)
  • Installation: Add to build.gradle.kts: implementation("io.ktor:ktor-network-tvosx64:3.2.0")

Core Imports

import io.ktor.network.sockets.*
import io.ktor.network.selector.*
import kotlinx.io.*

Basic Usage

import io.ktor.network.sockets.*
import io.ktor.network.selector.*
import kotlinx.coroutines.*
import kotlinx.io.*

// Create a selector manager for managing socket operations
val selectorManager = SelectorManager()

// TCP Client Example
val socket = aSocket(selectorManager).tcp().connect("localhost", 8080)
val connection = socket.connection()

// Send data
connection.output.writeStringUtf8("Hello, Server!")
connection.output.flush()

// Receive data
val response = connection.input.readUTF8Line()
println("Server response: $response")

// Close connection
socket.close()

// TCP Server Example
val serverSocket = aSocket(selectorManager).tcp().bind("0.0.0.0", 8080)
while (true) {
    val clientSocket = serverSocket.accept()
    launch {
        val connection = clientSocket.connection()
        val request = connection.input.readUTF8Line()
        connection.output.writeStringUtf8("Echo: $request")
        connection.output.flush()
        clientSocket.close()
    }
}

// UDP Example
val udpSocket = aSocket(selectorManager).udp().bind()
val packet = Buffer().apply { writeString("Hello UDP") }
val datagram = Datagram(packet, InetSocketAddress("localhost", 9090))
udpSocket.send(datagram)
val receivedDatagram = udpSocket.receive()

// Clean up
selectorManager.close()

Architecture

Ktor Network is built around several key components:

  • Socket Interfaces: Core abstractions (ASocket, Socket, ServerSocket) that define socket lifecycle and operations
  • Socket Builders: Fluent API (SocketBuilder, TcpSocketBuilder, UDPSocketBuilder) for creating and configuring sockets
  • Selector Management: Asynchronous I/O management (SelectorManager) for handling multiple socket operations concurrently
  • Address Types: Socket address abstractions (SocketAddress, InetSocketAddress, UnixSocketAddress) for different addressing schemes
  • Configuration System: Comprehensive socket options (SocketOptions) for tuning socket behavior
  • Channel Integration: ByteChannel-based I/O for reading and writing data to sockets

Capabilities

Socket Creation and Management

Core socket creation functionality using builder pattern with configurable options. Supports both TCP and UDP sockets with comprehensive lifecycle management.

fun aSocket(selector: SelectorManager): SocketBuilder

class SocketBuilder {
    fun tcp(): TcpSocketBuilder
    fun udp(): UDPSocketBuilder
}

Socket Creation

TCP Socket Operations

TCP client and server socket operations with support for connection establishment, data transmission, and server socket binding.

class TcpSocketBuilder {
    suspend fun connect(hostname: String, port: Int): Socket
    suspend fun connect(remoteAddress: SocketAddress): Socket
    suspend fun bind(hostname: String = "0.0.0.0", port: Int = 0): ServerSocket
    suspend fun bind(localAddress: SocketAddress? = null): ServerSocket
}

interface Socket : ReadWriteSocket, ABoundSocket, AConnectedSocket, CoroutineScope
interface ServerSocket : ASocket, ABoundSocket, Acceptable<Socket>

TCP Operations

UDP Socket Operations

UDP datagram socket operations supporting both bound and connected datagram sockets with packet-based communication.

class UDPSocketBuilder {
    suspend fun bind(localAddress: SocketAddress? = null): BoundDatagramSocket
    suspend fun connect(remoteAddress: SocketAddress, localAddress: SocketAddress? = null): ConnectedDatagramSocket
}

interface BoundDatagramSocket : ASocket, ABoundSocket, DatagramReadWriteChannel
interface ConnectedDatagramSocket : ASocket, ABoundSocket, AConnectedSocket, DatagramReadWriteChannel

UDP Operations

Socket Address Management

Socket address types and utilities for different addressing schemes including Internet addresses and Unix domain sockets.

sealed class SocketAddress

class InetSocketAddress(hostname: String, port: Int) : SocketAddress {
    val hostname: String
    val port: Int
    fun resolveAddress(): ByteArray?
}

class UnixSocketAddress(path: String) : SocketAddress {
    val path: String
    companion object {
        fun isSupported(): Boolean
    }
}

Socket Addresses

Socket Configuration

Comprehensive socket configuration options for tuning socket behavior including timeouts, buffer sizes, and protocol-specific options.

sealed class SocketOptions {
    var typeOfService: TypeOfService
    var reuseAddress: Boolean
    var reusePort: Boolean
    
    class TCPClientSocketOptions : PeerSocketOptions {
        var noDelay: Boolean
        var lingerSeconds: Int
        var keepAlive: Boolean?
        var socketTimeout: Long
    }
    
    class UDPSocketOptions : PeerSocketOptions {
        var broadcast: Boolean
    }
    
    class AcceptorOptions : SocketOptions {
        var backlogSize: Int
    }
}

Socket Configuration

I/O Operations

Socket I/O operations using ByteChannel integration for reading and writing data with support for both stream-based and packet-based communication.

interface ReadWriteSocket : ASocket, AReadable, AWritable

interface AReadable {
    fun attachForReading(channel: ByteChannel): WriterJob
}

interface AWritable {
    fun attachForWriting(channel: ByteChannel): ReaderJob
}

class Connection(
    val socket: Socket,
    val input: ByteReadChannel,
    val output: ByteWriteChannel
)

I/O Operations

Selector Management

Asynchronous I/O management for handling multiple socket operations concurrently using coroutine-based selection.

interface SelectorManager : CoroutineScope, Closeable {
    fun notifyClosed(selectable: Selectable)
    suspend fun select(selectable: Selectable, interest: SelectInterest)
}

fun SelectorManager(dispatcher: CoroutineContext = EmptyCoroutineContext): SelectorManager

enum class SelectInterest {
    READ, WRITE, ACCEPT, CONNECT
}

Selector Management