summaryrefslogtreecommitdiff
path: root/main.lua
blob: 025ab014efe046471026dde327b81e22fbbbd79d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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())