summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorheav <hheav3@gmail.com>2022-11-14 22:33:43 +0000
committerheav <hheav3@gmail.com>2022-11-14 22:33:43 +0000
commit0f043c1f93cfc7763f9d935d5b726dfcb7d1b6ef (patch)
tree269840c3acb4999b7fddf57ed7b43533cd53edd6
parent1aa3639c98c9d285ab7e101fdf8ee1c562d9a8dd (diff)
push broken horrible code
-rw-r--r--main.lua35
1 files changed, 35 insertions, 0 deletions
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