From 2efda12fcae7869bc3cc8782dbcaceae65d251f8 Mon Sep 17 00:00:00 2001 From: ame Date: Fri, 13 Jun 2025 20:31:24 -0500 Subject: clean net code and made net docs better --- docs/net/websocket.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 docs/net/websocket.md (limited to 'docs/net/websocket.md') diff --git a/docs/net/websocket.md b/docs/net/websocket.md new file mode 100644 index 0000000..5a82a70 --- /dev/null +++ b/docs/net/websocket.md @@ -0,0 +1,46 @@ +## ws + +net.wss(url) +net.ws(url)** + +both function identically, wss just uses openssl over socket + +will call each other when the url protocol mismatches the function + +can return an error + +```lua +net.wss("amyy.cc") -- connects to wss://amyy.cc +net.wss("ws://amyy.cc") -- identical to net.wss("amyy.cc" +``` + +```lua +local con = new.ws("amyy.cc") + +while true do + local frame = con:read() + print(frame.content) +end +``` + +### con:read + +con:read() + +reads the oldest unread frame from the server or wait for the next frame + +can return an error + +return table has the frame content (.content) and opcode (.opcode) + +### con:write + +con:write(content) + +sends a frame, returns nil or an error + +### con:close + +con:close() + +calls __gc early -- cgit v1.2.3