Package io.ktor.websocket

Types

Link copied to clipboard

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

Link copied to clipboard
class WebSockets constructor(pingIntervalMillis: Long, timeoutMillis: Long, maxFrameSize: Long, masking: Boolean, extensionsConfig: WebSocketExtensionsConfig) : CoroutineScope

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

Link copied to clipboard
interface WebSocketServerSession : WebSocketSession

Represents a server-side web socket session

Link copied to clipboard
class WebSocketUpgrade(call: ApplicationCall, protocol: String?, installExtensions: Boolean, handle: suspend WebSocketSession.() -> Unit) : OutgoingContent.ProtocolUpgrade

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
fun CoroutineScope.pinger(outgoing: SendChannel<Frame>, period: Duration, timeout: Duration, pool: ObjectPool<ByteBuffer> = KtorDefaultPool): SendChannel<Frame.Pong>

Launch pinger coroutine on CoroutineScope that is sending ping every specified period to outgoing channel, waiting for and verifying client's pong frames. It is also handling timeout and sending timeout close frame

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

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

fun Route.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 feature to be installed first

fun Route.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 feature to be installed first

Link copied to clipboard
fun Route.webSocketRaw(protocol: String? = null, handler: suspend WebSocketServerSession.() -> Unit)
fun Route.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 feature to be installed first

fun Route.webSocketRaw(path: String, protocol: String? = null, handler: suspend WebSocketServerSession.() -> Unit)
fun Route.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 feature to be installed first

fun Route.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 feature to be installed first

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

Properties

Link copied to clipboard
val WebSocketServerSession.application: Application

An application that started this web socket session