Web & HTTP5 exports
Raw Markdown/websocket/client
WebSocket client supporting text and binary frames, ping/pong, and graceful close.
Functions & symbols#
close#
function
Sends a close frame and shuts down the WebSocket connection.
| Parameter | Type | Optional | Description |
|---|---|---|---|
ws | WebSocket-Client | required | WebSocket client handle |
Returns:
Any(ws/close ws)connect#
function
Connects to a WebSocket server and returns an open `WebSocket-Client` handle.
| Parameter | Type | Optional | Description |
|---|---|---|---|
url | String | required | WebSocket endpoint (`ws://` or `wss://`) |
headers | Map | optional | Optional handshake headers |
options | Map | optional | Optional connection config |
Returns:
Any(let ws (ws/connect "wss://echo.websocket.events"))is-open?#
function
Returns `true` while the WebSocket connection remains open.
| Parameter | Type | Optional | Description |
|---|---|---|---|
ws | WebSocket-Client | required | WebSocket client handle |
Returns:
Any(ws/is-open? ws)receive#
function
Receives the next WebSocket frame `{:type :text|:binary|:ping|:pong|:close :data ...}`, or `()`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
ws | WebSocket-Client | required | Open WebSocket client |
non_blocking | Bool | optional | Optional non-blocking poll flag |
Returns:
Any(let msg (ws/receive ws))send#
function
Sends a text (`String`) or binary (`Slab`) WebSocket frame.
| Parameter | Type | Optional | Description |
|---|---|---|---|
ws | WebSocket-Client | required | Open WebSocket client |
message | String | Slab | required | Text or binary payload to transmit |
Returns:
Any(ws/send ws "hello")