ServerMessageSession

class ServerMessageSession(host: String = SERVER_HOST, port: Int, endpoint: String)

Manages a client WebSocket session to a server.

The session lifecycle is decoupled from the server's: if the underlying WebSocket drops, send transparently reconnects against the still-running server. Callers that need to stop the session explicitly should call close.

Parameters

host

server hostname

port

server port to connect to

endpoint

WebSocket endpoint path segment (without leading slash)

Constructors

Link copied to clipboard
constructor(host: String = SERVER_HOST, port: Int, endpoint: String)

Functions

Link copied to clipboard
suspend fun close()

Releases the session and the underlying HTTP client. After this call, no further sends will succeed without a new session being created externally.

Link copied to clipboard
suspend fun init(onReady: suspend () -> Unit = {})

Opens the WebSocket session (if not already open) and invokes onReady once the connection is established. Then blocks until the session is closed, so callers that rely on this method to keep their thread alive (e.g. the standalone server command) continue to work.

Link copied to clipboard
fun send(message: ServerMessage)

Sends a ServerMessage as a text frame, opening (or reopening) the session if needed.