summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'main.lua')
-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