KSocket

A coroutine-based socket implementation using AsynchronousSocketChannel.

Blocking - Though the underlying nio implementation is non-blocking, some operations may block briefly. In most cases this will be negligible. It's important to note the underlying does not set the dispatcher for operations. It is up to the user to decide the appropriate dispatcher.

Inheritors

Functions

Link copied to clipboard
abstract suspend fun bind(local: SocketAddress? = null)

Binds the socket to a local address. If the address is null, then the system will pick up an ephemeral port and a valid local address to bind the socket.

Link copied to clipboard
abstract suspend override fun close()

Closes the socket.

Link copied to clipboard
abstract suspend fun connect(endpoint: SocketAddress, timeout: Long = 0)

Connects this channel.

Link copied to clipboard
abstract suspend fun getChannel(): AsynchronousSocketChannel

Gets the underlying AsynchronousSocketChannel.

Link copied to clipboard
abstract suspend fun getInetAddress(): InetAddress?

Gets the remote InetAddress.

Link copied to clipboard
abstract suspend fun getInputStream(): KInputStream

Gets the input stream of the socket.

Link copied to clipboard
abstract suspend fun getKeepAlive(): Boolean

Gets the SO_KEEPALIVE option.

Link copied to clipboard
abstract suspend fun getLocalAddress(): InetAddress?

Gets the local InetAddress.

Link copied to clipboard
abstract suspend fun getLocalPort(): Int

Gets the local port number.

Link copied to clipboard
abstract suspend fun getLocalSocketAddress(): SocketAddress?

Gets the local socket address.

Link copied to clipboard
abstract suspend fun getOutputStream(): KOutputStream

Gets the output stream of the socket.

Link copied to clipboard
abstract suspend fun getPort(): Int

Gets the remote port number.

Link copied to clipboard
abstract suspend fun getReadTimeout(): Long

Gets the read timeout.

Link copied to clipboard
abstract suspend fun getReceiveBufferSize(): Int

Gets the SO_RCVBUF option.

Link copied to clipboard
abstract suspend fun getRemoteSocketAddress(): SocketAddress

Gets the remote socket address.

Link copied to clipboard
abstract suspend fun getReuseAddress(): Boolean

Gets the SO_REUSEADDR option.

Link copied to clipboard
abstract suspend fun getSendBufferSize(): Int

Gets the SO_SNDBUF option.

Link copied to clipboard
abstract suspend fun getSoLinger(): Int

Gets the SO_LINGER option.

Link copied to clipboard
abstract suspend fun getTcpNoDelay(): Boolean

Gets the TCP_NODELAY option.

Link copied to clipboard
abstract suspend fun getWriteTimeout(): Long

Gets the write timeout.

Link copied to clipboard
abstract suspend fun isBound(): Boolean

Checks if the socket is bound.

Link copied to clipboard
abstract suspend fun isClosed(): Boolean

Checks if the socket is closed.

Link copied to clipboard
abstract suspend fun isConnected(): Boolean

Checks if the socket is connected.

Link copied to clipboard
abstract suspend fun isInputShutdown(): Boolean

Checks if the input is shutdown.

Link copied to clipboard
abstract suspend fun isOutputShutdown(): Boolean

Checks if the output is shutdown.

Link copied to clipboard
abstract suspend fun setKeepAlive(keepAlive: Boolean)

Sets the SO_KEEPALIVE option.

Link copied to clipboard
abstract suspend fun setReadTimeout(timeout: Long?)

Sets the read timeout.

Link copied to clipboard
abstract suspend fun setReceiveBufferSize(size: Int)

Sets the SO_RCVBUF option.

Link copied to clipboard
abstract suspend fun setReuseAddress(reuse: Boolean)

Sets the SO_REUSEADDR option.

Link copied to clipboard
abstract suspend fun setSendBufferSize(size: Int)

Sets the SO_SNDBUF option.

Link copied to clipboard
abstract suspend fun setTcpNoDelay(on: Boolean)

Sets the TCP_NODELAY option.

Link copied to clipboard
abstract suspend fun setWriteTimeout(timeout: Long?)

Sets the write timeout.

Link copied to clipboard
abstract suspend fun shutdownInput()

Shuts down the input side of the socket.

Link copied to clipboard
abstract suspend fun shutdownOutput()

Shuts down the output side of the socket.