Skip to content

WebSocketServer

[Source]

WebSocket protocol handler that manages handshaking, framing, and connection lifecycle for a single WebSocket connection.

This class is NOT an actor — it lives inside the user's actor and handles protocol details. The user's actor implements WebSocketServerActor and stores this class as a field.

Use none() as the field default so that this is ref in the actor constructor body, then replace with create() or ssl():

actor MyHandler is WebSocketServerActor
  var _ws: WebSocketServer = WebSocketServer.none()

  new create(auth: lori.TCPServerAuth, fd: U32,
    config: WebSocketConfig val)
  =>
    _ws = WebSocketServer(auth, fd, this, config)

  fun ref _websocket(): WebSocketServer => _ws
class ref WebSocketServer is
  ServerLifecycleEventReceiver ref

Implements


Constructors

none

[Source]

Create a placeholder protocol instance.

Used as the default value for the _ws field in WebSocketServerActor implementations, allowing this to be ref in the actor constructor body. The placeholder is immediately replaced by create() or ssl() — its methods must never be called.

new ref none()
: WebSocketServer ref^

Returns


create

[Source]

Create a plain WebSocket (WS) connection handler.

new ref create(
  auth: TCPServerAuth val,
  fd: U32 val,
  server_actor: WebSocketServerActor ref,
  config: WebSocketConfig val)
: WebSocketServer ref^

Parameters

Returns


ssl

[Source]

Create a secure WebSocket (WSS) connection handler.

new ref ssl(
  auth: TCPServerAuth val,
  ssl_ctx: SSLContext val,
  fd: U32 val,
  server_actor: WebSocketServerActor ref,
  config: WebSocketConfig val)
: WebSocketServer ref^

Parameters

Returns


Public Functions

send_text

[Source]

Send a text message to the client.

fun ref send_text(
  data: String val)
: None val

Parameters

Returns


send_binary

[Source]

Send a binary message to the client.

fun ref send_binary(
  data: Array[U8 val] val)
: None val

Parameters

Returns


close

[Source]

Initiate a close handshake with the client.

Sends a close frame and transitions to the Closing state. The connection will close after the client responds with its own close frame, or if TCP drops.

fun ref close(
  code: (CloseNormal val | CloseGoingAway val | CloseProtocolError val | 
    CloseUnsupportedData val | CloseInvalidPayload val | ClosePolicyViolation val | 
    CloseMessageTooBig val | CloseInternalError val) = reference,
  reason: String val = "")
: None val

Parameters

Returns