Tanguv0.35.0
Web & HTTP5 exports
Raw Markdown

/websocket/client

WebSocket client supporting text and binary frames, ping/pong, and graceful close.

(use /websocket/client)

Functions & symbols#

close#

function
(close ws) -> None

Sends a close frame and shuts down the WebSocket connection.

ParameterTypeOptionalDescription
wsWebSocket-ClientrequiredWebSocket client handle
Returns:Any
(ws/close ws)

connect#

function
(connect url [headers [options]]) -> WebSocket-Client

Connects to a WebSocket server and returns an open `WebSocket-Client` handle.

ParameterTypeOptionalDescription
urlStringrequiredWebSocket endpoint (`ws://` or `wss://`)
headersMapoptionalOptional handshake headers
optionsMapoptionalOptional connection config
Returns:Any
(let ws (ws/connect "wss://echo.websocket.events"))

is-open?#

function
(is-open? ws) -> Bool

Returns `true` while the WebSocket connection remains open.

ParameterTypeOptionalDescription
wsWebSocket-ClientrequiredWebSocket client handle
Returns:Any
(ws/is-open? ws)

receive#

function
(receive ws [non-blocking]) -> (Or Map None)

Receives the next WebSocket frame `{:type :text|:binary|:ping|:pong|:close :data ...}`, or `()`.

ParameterTypeOptionalDescription
wsWebSocket-ClientrequiredOpen WebSocket client
non_blockingBooloptionalOptional non-blocking poll flag
Returns:Any
(let msg (ws/receive ws))

send#

function
(send ws message) -> None

Sends a text (`String`) or binary (`Slab`) WebSocket frame.

ParameterTypeOptionalDescription
wsWebSocket-ClientrequiredOpen WebSocket client
messageString | SlabrequiredText or binary payload to transmit
Returns:Any
(ws/send ws "hello")