webSocket

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

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

DefaultWebSocketSession.incoming will never contain any control frames and no fragmented frames could be found. Default WebSocket implementation is handling ping/pongs, timeouts, close frames and reassembling fragmented frames.

When a WebSocket session is created, a handler lambda will be called with WebSocket session instance on receiver. Once handler function returns, the websocket termination sequence will be scheduled, so you shouldn't use DefaultWebSocketSession anymore. However, WebSocket could live for a while until close sequence completed or a timeout exceeds.


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

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

DefaultWebSocketSession.incoming will never contain any control frames and no fragmented frames could be found. Default WebSocket implementation is handling ping/pongs, timeouts, close frames and reassembling fragmented frames.

When a websocket session is created, a handler lambda will be called with WebSocket session instance on receiver. Once handler function returns, the WebSocket termination sequence will be scheduled so you shouldn't use DefaultWebSocketSession anymore. However, WebSocket could live for a while until close sequence completed or a timeout exceeds.