Package io.ktor.network.sockets

Types

Link copied to clipboard
interface ABoundSocket

Represents a bound socket

Link copied to clipboard
interface Acceptable<out S : ASocket> : ASocket

Represents a socket source, for example server socket

Link copied to clipboard
interface AConnectedSocket : AWritable

Represent a connected socket

Link copied to clipboard
interface AReadable

Represent a readable socket

Link copied to clipboard
interface ASocket : DisposableHandle

Base type for all async sockets

Link copied to clipboard
interface AWritable

Represents a writable socket

Link copied to clipboard

Represents a bound datagram socket

Link copied to clipboard
interface Configurable<out T : Configurable<T, Options>, Options : SocketOptions>

Represent a configurable socket

Link copied to clipboard

Represents a connected datagram socket.

Link copied to clipboard
class Connection(socket: Socket, input: <ERROR CLASS>, output: <ERROR CLASS>)

Represents a connected socket with its input and output

Link copied to clipboard
class Datagram(packet: <ERROR CLASS>, address: SocketAddress)

UDP datagram with packet content targeted to address

Link copied to clipboard
interface DatagramReadChannel

A channel for receiving datagrams

Link copied to clipboard
interface DatagramReadWriteChannel : DatagramReadChannel, DatagramWriteChannel

A channel for sending and receiving datagrams

Link copied to clipboard
interface DatagramWriteChannel

A channel for sending datagrams

Link copied to clipboard
expect class InetSocketAddress(hostname: String, port: Int) : SocketAddress
actual class InetSocketAddress(hostname: String, port: Int) : SocketAddress
actual data class InetSocketAddress(hostname: String, port: Int) : SocketAddress
Link copied to clipboard
interface ReadWriteSocket : ASocket, AReadable, AWritable

Represents both readable and writable socket

Link copied to clipboard
interface ServerSocket : ASocket, ABoundSocket, Acceptable<Socket>

Represents a server bound socket ready for accepting connections

Link copied to clipboard
interface Socket : ReadWriteSocket, ABoundSocket, AConnectedSocket

Represents a connected socket

Link copied to clipboard
expect sealed class SocketAddress
actual sealed class SocketAddress
actual sealed class SocketAddress
Link copied to clipboard
class SocketBuilder : Configurable<SocketBuilder, SocketOptions>

Socket builder

Link copied to clipboard
sealed class SocketOptions

Socket options builder

Link copied to clipboard
expect class SocketTimeoutException
actual typealias SocketTimeoutException = SocketTimeoutException
actual class SocketTimeoutException
Link copied to clipboard
class TcpSocketBuilder(selector: SelectorManager, options: SocketOptions) : Configurable<TcpSocketBuilder, SocketOptions>

TCP socket builder

Link copied to clipboard
value class TypeOfService(value: UByte)

An inline class to hold a IP ToS value

Link copied to clipboard

UDP socket builder

Link copied to clipboard
expect class UnixSocketAddress(path: String) : SocketAddress
actual class UnixSocketAddress(path: String) : SocketAddress
actual data class UnixSocketAddress(path: String) : SocketAddress

Functions

Link copied to clipboard
fun aSocket(selector: SelectorManager): SocketBuilder

Start building a socket

Link copied to clipboard
suspend fun ASocket.awaitClosed()

Await until socket close

Link copied to clipboard
suspend fun TcpSocketBuilder.connect(remoteAddress: SocketAddress, configure: SocketOptions.TCPClientSocketOptions.() -> Unit = {}): Socket
Link copied to clipboard
fun Socket.connection(): Connection

Opens socket input and output channels and returns connection object

Link copied to clipboard
fun AReadable.openReadChannel(): <ERROR CLASS>

Open a read channel, could be done only once

Link copied to clipboard
fun AWritable.openWriteChannel(autoFlush: Boolean = false): <ERROR CLASS>

Open a write channel, could be opened only once

Link copied to clipboard
fun <T : Configurable<T, *>> T.tcpNoDelay(): T

Set TCP_NODELAY socket option to disable the Nagle algorithm.

Link copied to clipboard
fun SocketAddress.toJavaAddress(): SocketAddress

Properties

Link copied to clipboard
val ASocket.isClosed: Boolean

Check if the socket is closed