Package io.ktor.server.websocket

Types

Link copied to clipboard
interface DefaultWebSocketServerSession : WebSocketServerSession

Represents a server-side web socket session with all default implementations

Link copied to clipboard
class WebSockets : CoroutineScope

WebSockets support plugin. It is required to be installed first before binding any websocket endpoints

Link copied to clipboard
interface WebSocketServerSession

Represents a server-side web socket session

Link copied to clipboard
class WebSocketUpgrade(call: <ERROR CLASS>, protocol: String?, installExtensions: Boolean, handle: suspend <ERROR CLASS>.() -> Unit)

An OutgoingContent response object that could be used to respond(): it will cause application engine to perform HTTP upgrade and start websocket RAW session.

Functions

Link copied to clipboard
inline suspend fun <T : Any> WebSocketServerSession.receiveDeserialized(): T

Dequeues a frame and deserializes it to the type T using WebSocket content converter. May throw an exception WebsocketDeserializeException if the converter can't deserialize frame data to type T. May throw WebsocketDeserializeException if the received frame type is not Frame.Text or Frame.Binary. In this case, WebsocketDeserializeException.frame contains the received frame. May throw ClosedReceiveChannelException if a channel was closed

Link copied to clipboard
inline suspend fun <T : Any> WebSocketServerSession.sendSerialized(data: T)

Serializes data to a frame and enqueues this frame. May suspend if the outgoing queue is full. If the outgoing channel is already closed, throws an exception, so it is impossible to transfer any message. Frames sent after a Close frame are silently ignored. Note that a Close frame could be sent automatically in reply to a peer's Close frame unless it is a raw WebSocket session.

Link copied to clipboard
fun <ERROR CLASS>.webSocket(protocol: String? = null, handler: suspend DefaultWebSocketServerSession.() -> Unit)

Bind websocket at the current route optionally checking for websocket protocol (ignored if null) Requires WebSockets plugin to be installed first

fun <ERROR CLASS>.webSocket(path: String, protocol: String? = null, handler: suspend DefaultWebSocketServerSession.() -> Unit)

Bind websocket at the current route + path optionally checking for websocket protocol (ignored if null) Requires WebSockets plugin to be installed first

fun <ERROR CLASS>.webSocket(webSocketProtocol: String, webSocketHandler: suspend DefaultWebSocketServerSession.() -> Unit, nothing: Nothing? = null)

Bind websocket at the current route optionally checking for websocket protocol (ignored if null) Requires WebSockets plugin to be installed first

Link copied to clipboard
fun <ERROR CLASS>.webSocketRaw(protocol: String? = null, handler: suspend WebSocketServerSession.() -> Unit)
fun <ERROR CLASS>.webSocketRaw(protocol: String? = null, negotiateExtensions: Boolean = false, handler: suspend WebSocketServerSession.() -> Unit)

Bind RAW websocket at the current route optionally checking for websocket protocol (ignored if null) Requires WebSockets plugin to be installed first

fun <ERROR CLASS>.webSocketRaw(path: String, protocol: String? = null, handler: suspend WebSocketServerSession.() -> Unit)
fun <ERROR CLASS>.webSocketRaw(path: String, protocol: String? = null, negotiateExtensions: Boolean = false, handler: suspend WebSocketServerSession.() -> Unit)

Bind RAW websocket at the current route + path optionally checking for websocket protocol (ignored if null) Requires WebSockets plugin to be installed first

fun <ERROR CLASS>.webSocketRaw(webSocketProtocol: String, webSocketHandler: suspend WebSocketServerSession.() -> Unit, nothing: Nothing? = null)

Bind RAW websocket at the current route optionally checking for websocket protocol (ignored if null) Requires WebSockets plugin to be installed first

Link copied to clipboard
fun WebSockets(pingInterval: Duration?, timeout: Duration, maxFrameSize: Long, masking: Boolean): WebSockets

WebSockets support plugin. It is required to be installed first before binding any websocket endpoints

fun WebSockets(pingInterval: Duration?, timeout: Duration, maxFrameSize: Long, masking: Boolean): WebSockets

Properties

Link copied to clipboard
val WebSocketServerSession.application: <ERROR CLASS>

An application that started this web socket session

Link copied to clipboard
val WebSocketServerSession.converter: <ERROR CLASS>?

Converter for web socket session

Link copied to clipboard
var DefaultWebSocketServerSession.pingInterval: Duration?

Ping interval or null to disable pinger. Please note that pongs will be handled despite this setting.

Link copied to clipboard
val WebSockets.pingInterval: Duration?
Link copied to clipboard
var WebSockets.WebSocketOptions.pingPeriod: Duration?
Link copied to clipboard
var DefaultWebSocketServerSession.timeout: Duration

A timeout to wait for pong reply to ping otherwise the session will be terminated immediately. It doesn't have any effect if pingInterval is null (pinger is disabled).

Link copied to clipboard
val WebSockets.timeout: Duration
Link copied to clipboard
var WebSockets.WebSocketOptions.timeout: Duration