class

WebSocket

class WebSocket : Obj

WebSocket is used for both client and server web socket messaging. Current implementation only supports basic non-fragmented text or binary messages.

methods openClient

Open a client connection

receive

Receive a message which is returned as either a Str or Buf

isClosed

Return true if this socket has been closed

socketOptions

Access to socket options for this request

close

Close the web socket

send

Send a message which must be either a Str of Buf

openServer

Upgrade a server request to a WebSocket

close Bool close()

Close the web socket

isClosed Bool isClosed()

Return true if this socket has been closed

openClient static WebSocket openClient(Uri uri, [Str:Str]? headers)

Open a client connection. The URI must have a "ws" or "wss" scheme. The headers parameter defines additional HTTP headers to include in the connection request.

openServer static WebSocket openServer(WebReq req, WebRes res)

Upgrade a server request to a WebSocket. Raise IOErr is there is any problems during the handshake in which case the calling WebMod should return a 400 response.

Callers should set the Sec-WebSocket-Protocol response header before calling this method. However, if not set then this call will set it to the request header value for Sec-WebSocket-Protocol (if available).

Note: once this method completes, the socket is now owned by the WebSocket instance and not the web server (wisp); it must be explicitly closed to prevent a file handle leak.

receive Obj? receive()

Receive a message which is returned as either a Str or Buf. Raise IOErr if socket has error or is closed.

send Void send(Obj msg)

Send a message which must be either a Str of Buf. Bufs are sent using their full contents irrelevant of their current position.

socketOptions @Deprecated { msg=... }
SocketOptions socketOptions()

Access to socket options for this request.

Haxall 4.0.5 ∙ 24-Feb-2026 14:33 EST