WebSockets Subpackage (ws)
The ws module provides zero-dependency full-duplex WebSocket client primitives for connecting to real-time microservices, streaming feeds, and chat protocols.
API Reference
ws.connect(url: String): WebSocket
Establishes a WebSocket connection to the target URL (e.g. ws://127.0.0.1:8080/feed).
ws.send(socket: WebSocket, message: String): Int
Sends a text payload across the socket. Returns total payload bytes sent, or -1 on error.
ws.recv(socket: WebSocket): String
Reads the next available text message from the socket buffer. Returns an empty string if no messages are queued.
ws.close(socket: WebSocket): Int
Closes the underlying TCP stream connection. Returns 0 on success.