Package-level declarations

Types

Link copied to clipboard
data class CloseReason(val code: Short, val message: String)

A WebSocket close reason.

Link copied to clipboard

A default WebSocket session with ping-pong and timeout processing and built-in closeReason population.

Link copied to clipboard
expect sealed class Frame

A frame received or ready to be sent. It is not reusable and not thread-safe.

actual sealed class Frame

A frame received or ready to be sent. It is not reusable and not thread-safe

actual sealed class Frame

A frame received or ready to be sent. It is not reusable and not thread-safe

actual sealed class Frame

A frame received or ready to be sent. It is not reusable and not thread-safe

Link copied to clipboard
Link copied to clipboard
class FrameTooBigException(val frameSize: Long) : Exception, CopyableThrowable<FrameTooBigException>

Raised when the frame is bigger than allowed in a current WebSocket session.

Link copied to clipboard

A WebSocket frame type.

Link copied to clipboard
class ProtocolViolationException(val violation: String) : Exception, CopyableThrowable<ProtocolViolationException>

Raised when peers send frames which violate the Websocket RFC

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Compress and decompress WebSocket frames to reduce amount of transferred bytes.

Link copied to clipboard

A WebSocket extension instance. This instance is created for each WebSocket request, for every installed extension by WebSocketExtensionFactory.

Link copied to clipboard

A factory that defines a WebSocket extension. The factory is used in pair with the WebSocketExtensionsConfig.install method to install the WebSocket extension in client or server.

Link copied to clipboard
class WebSocketExtensionHeader(val name: String, val parameters: List<String>)

A parsed Sec-WebSocket-Accept header item representation.

Link copied to clipboard

Extensions configuration for the WebSocket client and server plugins.

Link copied to clipboard
class WebSocketReader(byteChannel: ByteReadChannel, val coroutineContext: CoroutineContext, var maxFrameSize: Long, pool: ObjectPool<ByteBuffer> = KtorDefaultPool) : CoroutineScope

Class that continuously reads a byteChannel and converts into Websocket Frame exposing them in incoming.

Link copied to clipboard
interface WebSocketSession : CoroutineScope

A WebSocket session between two peers.

Link copied to clipboard
class WebSocketWriter(writeChannel: ByteWriteChannel, val coroutineContext: CoroutineContext, var masking: Boolean = false, val pool: ObjectPool<ByteBuffer> = KtorDefaultPool) : CoroutineScope

Class that processes written outgoing Websocket Frame, serializes them and writes the bits into the writeChannel.

Functions

Link copied to clipboard
suspend fun WebSocketSession.close(reason: CloseReason = CloseReason(CloseReason.Codes.NORMAL, ""))

Sends a close frame with the specified reason. May suspend if the outgoing channel is full. The specified reason could be ignored if there was already close frame sent (for example in reply to a peer close frame). It also may do nothing when a session or an outgoing channel is already closed due to any reason.

suspend fun WebSocketSession.close(cause: Throwable?)

Closes with the reason depending on cause or normally if the cause is null.

Link copied to clipboard

Closes a session with normal or error close reason, depending on whether cause is cancellation or not.

Link copied to clipboard
fun DefaultWebSocketSession(session: WebSocketSession, pingInterval: Long = -1L, timeoutMillis: Long = 15000): DefaultWebSocketSession

Creates DefaultWebSocketSession from a session.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Parses the Sec-WebSocket-Accept header.

Link copied to clipboard
expect fun RawWebSocket(input: ByteReadChannel, output: ByteWriteChannel, maxFrameSize: Long = Int.MAX_VALUE.toLong(), masking: Boolean = false, coroutineContext: CoroutineContext): WebSocketSession

Creates a RAW web socket session from connection.

actual fun RawWebSocket(input: ByteReadChannel, output: ByteWriteChannel, maxFrameSize: Long, masking: Boolean, coroutineContext: CoroutineContext): WebSocketSession

Creates a RAW web socket session from connection

actual fun RawWebSocket(input: ByteReadChannel, output: ByteWriteChannel, maxFrameSize: Long, masking: Boolean, coroutineContext: CoroutineContext): WebSocketSession

Creates a RAW web socket session from connection

actual fun RawWebSocket(input: ByteReadChannel, output: ByteWriteChannel, maxFrameSize: Long, masking: Boolean, coroutineContext: CoroutineContext): WebSocketSession

Creates a RAW web socket session from connection

Link copied to clipboard

Reads binary content from the frame. For fragmented frames only returns this fragment.

Link copied to clipboard
suspend fun ByteReadChannel.readFrame(maxFrameSize: Long, lastOpcode: Int): Frame

Reads bits from ByteReadChannel and converts into a WebSocket Frame.

Link copied to clipboard

Reads the close reason from the close frame or null if no close reason is provided.

Link copied to clipboard

Reads text content from the text frame. Shouldn't be used for fragmented frames: such frames need to be reassembled first.

Link copied to clipboard
suspend fun WebSocketSession.send(content: ByteArray)

Enqueues a final binary frame for sending with the specified content.

suspend fun WebSocketSession.send(content: String)

Enqueues a text frame for sending with the specified content.

Link copied to clipboard
suspend fun ByteWriteChannel.writeFrame(frame: Frame, masking: Boolean)

Serializes WebSocket Frame and writes the bits into the ByteWriteChannel. If masking is true, then data will be masked with random mask