Files
marqdo/ext/net/websocket.mq.md
cflmy 9331af78e2 release(2.8.0): 合入 CHANGELOG/README/发版说明/skills prove 任务;CI 链接指向 doc/releases
- CHANGELOG.md:v2.8.0 条目(中英双语);
- README.md:版本行 2.7.1→2.8.0 + 愿景第 6 条(知识可证明);
- doc/releases/v2.8.0.md:双语发版说明(亮点/用法/已知限制);
- skills/marqdo-dev/index.mq.md:新增 prove 任务(路径/目录模式/
  require_lean/json;参数用 + 行声明升参,check 与 narrative-ratio 通过);
- 设计文档 §12.5 标记已合入;发版链接统一指向 doc/releases/v2.8.0.md。
2026-11-18 10:29:26 +08:00

4.5 KiB
Executable File
Raw Permalink Blame History

markup, title, description, import
markup title description import
occlusion ext/net/websocket WebSocket client Resource (ADR 0007).
plugin sys table
lib/plugin.mq.md lib/sys.mq.md lib/table.mq.md

This resource performs one bounded native WebSocket exchange and closes it. The network entry shows the input contract and the distinction from pure URL encoding. Configure a controlled ws/wss endpoint and inspect ok/error, timeout and reply data before acting. New transport behavior belongs in the web plugin, with local tests for failed connections and oversized replies; this resource is not a persistent subscription service.

_load

返回 类型 说明
result any No business value on completion; a missing native plugin reports the cause and exits this run.

Resolve and load the native web plugin before resource operations; missing binaries stop this run.

We retain p = Locate the installed native plugin.

  1. p We Load the native plugin required by this operation.

We [Print the prepared message](print(text="ext/net: native web plugin not found")). We End this run with the selected exit status. Return None.

route

参数 类型 默认 说明
app any required Prepared application returned by web.prepare
path text required Declared WebSocket path, including optional path captures
mode text "echo" echo, drain, broadcast or room
room_key text "" Room template required by room mode
presence bool False Publish native room presence messages
require_auth any None None keeps private broadcast/room defaults; False explicitly opens a local demo
on_message text "" Optional declared Marqdo callback member
返回 类型 说明
result map Updated app with this explicitly declared WebSocket route

Use app, path, mode="echo", room_key="", presence=False, require_auth=None and on_message="" to bind a server transport before web.listen. This function belongs to the network resource; it does not change Document layout or start a socket. Retain the returned app because native resource updates produce a new value. Room mode requires a room_key template; captures such as {id} select the room at request time. Broadcast and room routes require login unless the caller explicitly opts out. Public local demos should say why require_auth=False is intentional. Presence and callbacks retain the native transport's bounded message handling; they are not a client subscription object.

We Load the native transport implementation. Return [Register this declared WebSocket transport](web_app_route_ws(app=app, path=path, echo=None, mode=mode, room_key=room_key, on_message=on_message, presence=presence, require_auth=require_auth)).

ws

参数 类型 默认 说明
timeout_sec any 30 Request/response timeout in seconds
返回 类型 说明
result any WebSocket client helper.

Use timeout_sec=30 as the inputs for this operation.

WebSocket client helper.

We Load the native plugin required by this operation.

out =

timeout_sec _type
timeout_sec ws

Return out.

connect

参数 类型 默认 说明
url any required Resource connection URL; scheme selects the documented backend
message any "" Outgoing WebSocket or application message
headers any None HTTP request header record or None
返回 类型 说明
result any Single request–response: connect to url, send message, collect up to 256 server text replies (each up to 1 MiB), close. Transport errors and timeouts return {ok:false, error} instead of looking like an empty successful reply.

Use url, message="", headers=None as the inputs for this operation.

Single request–response: connect to url, send message, collect up to 256 server text replies (each up to 1 MiB), close. Transport errors and timeouts return {ok:false, error} instead of looking like an empty successful reply.

We retain timeout = Read timeout_sec field). Return [Single request–response: connect to url, send message, collect up to 256 server text replies (each up to 1 MiB), close](web_ws_connect(url=url, message=message, headers=headers, timeout_sec=timeout)).