CtrlK
BlogDocsLog inGet started
Tessl Logo

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

Pending
Overview
Eval results
Files

socket-creation.mddocs/

Socket Creation

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

Capabilities

Socket Builder Factory

Creates a socket builder instance that provides access to TCP and UDP socket builders.

/**
 * Start building a socket
 * @param selector SelectorManager for managing socket operations
 * @returns SocketBuilder instance for creating TCP or UDP sockets
 */
fun aSocket(selector: SelectorManager): SocketBuilder

Usage Example:

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

val selectorManager = SelectorManager()
val socketBuilder = aSocket(selectorManager)

// Create TCP socket builder
val tcpBuilder = socketBuilder.tcp()

// Create UDP socket builder  
val udpBuilder = socketBuilder.udp()

Socket Builder

Main socket builder providing access to protocol-specific builders.

/**
 * Socket builder for creating TCP and UDP sockets
 */
class SocketBuilder : Configurable<SocketBuilder, SocketOptions> {
    /** Build TCP socket builder */
    fun tcp(): TcpSocketBuilder
    
    /** Build UDP socket builder */
    fun udp(): UDPSocketBuilder
    
    /** Current socket options */
    var options: SocketOptions
}

Configurable Interface

Interface for socket configuration management used by all socket builders.

/**
 * Represents a configurable socket with options
 */
interface Configurable<out T : Configurable<T, Options>, Options : SocketOptions> {
    /** Current socket options */
    var options: Options
    
    /** Configure socket options in block function */
    fun configure(block: Options.() -> Unit): T
}

Usage Example:

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

val selectorManager = SelectorManager()

// Configure socket with options
val socket = aSocket(selectorManager)
    .configure {
        reuseAddress = true
        reusePort = true
        typeOfService = TypeOfService.IPTOS_LOWDELAY
    }
    .tcp()
    .connect("localhost", 8080)

Base Socket Interface

Base interface for all socket types providing lifecycle management.

/**
 * Base type for all async sockets
 */
interface ASocket : Closeable, DisposableHandle {
    /** Represents a socket lifetime, completes at socket closure */
    val socketContext: Job
}

/** Check if the socket is closed */
val ASocket.isClosed: Boolean

/** Await until socket close */
suspend fun ASocket.awaitClosed()

Socket Address Interfaces

Interfaces for socket address information.

/**
 * Represents a bound socket
 */
interface ABoundSocket {
    /** Local socket address. Could throw an exception if no address bound yet. */
    val localAddress: SocketAddress
}

/**
 * Represents a connected socket
 */
interface AConnectedSocket {
    /** Remote socket address. Could throw an exception if the peer is not yet connected or already disconnected. */
    val remoteAddress: SocketAddress
}

Usage Example:

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

val selectorManager = SelectorManager()

// Create and connect a socket
val socket = aSocket(selectorManager).tcp().connect("localhost", 8080)

// Check socket status
println("Socket closed: ${socket.isClosed}")
println("Local address: ${socket.localAddress}")
println("Remote address: ${socket.remoteAddress}")

// Wait for socket to close
socket.awaitClosed()

// Clean up
selectorManager.close()

Types

class SocketTimeoutException(message: String) : IOException

Install with Tessl CLI

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

docs

index.md

io-operations.md

selector-management.md

socket-addresses.md

socket-configuration.md

socket-creation.md

tcp-operations.md

udp-operations.md

tile.json