websocket
Functions for creating, managing, and interacting with WebSocket connections, including sending and receiving data, handling events, and connection lifecycle control.
Last updated
Functions for creating, managing, and interacting with WebSocket connections, including sending and receiving data, handling events, and connection lifecycle control.
Last updated
-- Connect (returns nil on failure)
local ws = websocket.connect("ws://localhost:8080")
if not ws then
print("connection failed")
return
end
-- Send text or binary
ws:send("hello world")
ws:send_binary("data")
-- Poll for incoming messages (non-blocking, returns nil if none queued)
local msg = ws:recv()
-- Check state
ws:is_connected() -- true while connection is live
ws:is_closed() -- true after server sends a close frame
-- Disconnect
ws:close()