DefaultWebSocketSession

interface DefaultWebSocketSession : WebSocketSession

Default websocket session with ping-pong and timeout processing and built-in closeReason population

Functions

Link copied to clipboard
abstract suspend fun flush()

Flush all outstanding messages and suspend until all earlier sent messages will be written. Could be called at any time even after close. May return immediately if the connection is already terminated. However it may also fail with an exception (or cancellation) at any point due to session failure. Please note that flush doesn't guarantee that frames were actually delivered.

Link copied to clipboard
open suspend fun send(frame: Frame)

Enqueue frame, may suspend if outgoing queue is full. May throw an exception if outgoing channel is already closed so it is impossible to transfer any message. Frames that were sent after close frame could be silently ignored. Please note that close frame could be sent automatically in reply to a peer close frame unless it is raw websocket session.

Link copied to clipboard
abstract fun start(negotiatedExtensions: List<WebSocketExtension<*>> = emptyList())

Start WebSocket conversation.

Link copied to clipboard
abstract fun terminate()

Initiate connection termination immediately. Termination may complete asynchronously.

Properties

Link copied to clipboard
abstract val closeReason: Deferred<CloseReason?>

A close reason for this session. It could be null if a session is terminated with no close reason (for example due to connection failure).

Link copied to clipboard
abstract val coroutineContext: CoroutineContext
Link copied to clipboard
abstract val extensions: List<WebSocketExtension<*>>

Negotiated WebSocket extensions.

Link copied to clipboard
abstract val incoming: ReceiveChannel<Frame>

Incoming frames channel

Link copied to clipboard
abstract var masking: Boolean

Enable or disable masking output messages by a random xor mask. Please note that changing this flag on the fly could be applied to the messages already sent (enqueued earlier) as the sending pipeline works asynchronously

Link copied to clipboard
abstract var maxFrameSize: Long

Specifies frame size limit. Connection will be closed if violated

Link copied to clipboard
abstract val outgoing: SendChannel<Frame>

Outgoing frames channel. It could have limited capacity so sending too much frames may lead to suspension at corresponding send invocations. It also may suspend if a peer doesn't read frames for some reason.

Link copied to clipboard
abstract var pingIntervalMillis: Long

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

Link copied to clipboard
abstract var timeoutMillis: Long

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