From 0f043c1f93cfc7763f9d935d5b726dfcb7d1b6ef Mon Sep 17 00:00:00 2001 From: heav Date: Mon, 14 Nov 2022 22:33:43 +0000 Subject: push broken horrible code --- main.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 main.lua diff --git a/main.lua b/main.lua new file mode 100644 index 0000000..025ab01 --- /dev/null +++ b/main.lua @@ -0,0 +1,35 @@ +print("it is already far, far too late.") + +local cqueues = require("cqueues") +local cq = cqueues.new() + +local httpserver = require("http.server") +local websocket = require("http.websocket") + +function onstream(server, stream) + print("stream you.") + cq:wrap(function() + local s, ws = pcall(websocket.new_from_stream,stream) + if not s then + stream:shutdown() + return + end + ws:accept() + while true do + local data = ws:receive() + ws:send(data) + end + end) +end + +local sv = httpserver.listen { + host = "127.0.0.1", + port = "61111", + onstream = onstream, +} + +cq:wrap(function() + sv:loop() +end) + +assert(cq:loop()) \ No newline at end of file -- cgit v1.2.3