ktor-network / io.ktor.network.sockets

Package io.ktor.network.sockets

Types

ABoundSocket

interface ABoundSocket

Represents a bound socket

AConnectedSocket

interface AConnectedSocket : AWritable

Represent a connected socket

AReadable

interface AReadable

Represent a readable socket

ASocket

interface ASocket : DisposableHandle

Base type for all async sockets

AWritable

interface AWritable

Represents a writable socket

Acceptable

interface Acceptable<out S : ASocket> : ASocket

Represents a socket source, for example server socket

BoundDatagramSocket

interface BoundDatagramSocket : ASocket, ABoundSocket, AReadable, DatagramReadWriteChannel

Represents a bound datagram socket

Configurable

interface Configurable<out T : Configurable<T, Options>, Options : SocketOptions>

Represent a configurable socket

ConnectedDatagramSocket

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

Represents a connected datagram socket.

Connection

class Connection

Represents a connected socket with its input and output

Datagram

class Datagram

UDP datagram with packet content targeted to address

DatagramReadChannel

interface DatagramReadChannel

A channel for receiving datagrams

DatagramReadWriteChannel

interface DatagramReadWriteChannel : DatagramReadChannel, DatagramWriteChannel

A channel for sending and receiving datagrams

DatagramWriteChannel

interface DatagramWriteChannel

A channel for sending datagrams

ReadWriteSocket

interface ReadWriteSocket : ASocket, AReadable, AWritable

Represents both readable and writable socket

ServerSocket

interface ServerSocket : ASocket, ABoundSocket, Acceptable<Socket>

Represents a server bound socket ready for accepting connections

Socket

interface Socket : ReadWriteSocket, ABoundSocket, AConnectedSocket

Represents a connected socket

SocketBuilder

class SocketBuilder : Configurable<SocketBuilder, SocketOptions>

Socket builder

SocketOptions

sealed class SocketOptions

Socket options builder

SocketTimeoutException

expect class SocketTimeoutException

TcpSocketBuilder

class TcpSocketBuilder : Configurable<TcpSocketBuilder, SocketOptions>

TCP socket builder

TypeOfService

class TypeOfService

An inline class to hold a IP ToS value

UDPSocketBuilder

class UDPSocketBuilder : Configurable<UDPSocketBuilder, UDPSocketOptions>

UDP socket builder

Type Aliases

SocketTimeoutException

actual typealias SocketTimeoutException = SocketTimeoutException

Properties

isClosed

val ASocket.isClosed: Boolean

Check if the socket is closed

Functions

aSocket

fun aSocket(selector: SelectorManager): SocketBuilder

Start building a socket

awaitClosed

suspend fun ASocket.awaitClosed(): Unit

Await until socket close

connect

suspend fun TcpSocketBuilder.connect(remoteAddress: SocketAddress, configure: TCPClientSocketOptions.() -> Unit = {}): Socket

connection

fun Socket.connection(): Connection

Opens socket input and output channels and returns connection object

openReadChannel

fun AReadable.openReadChannel(): ByteReadChannel

Open a read channel, could be done only once

openWriteChannel

fun AWritable.openWriteChannel(autoFlush: Boolean = false): ByteWriteChannel

Open a write channel, could be opened only once

tcpNoDelay

fun <T : Configurable<T, *>> T.tcpNoDelay(): T

Set TCP_NODELAY socket option to disable the Nagle algorithm.