Created
December 10, 2015 19:45
-
-
Save cablehead/0a7ec810fe095d1106bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local levee = require("levee") | |
local h = levee.Hub() | |
local connections = 0 | |
-- HTTP endpoint to see number of connections | |
h:spawn(function() | |
local err, http = h.http:listen(8000) | |
while true do | |
local err, conn = http:recv() | |
if err then break end | |
local err, req = conn:recv() | |
req.response:send({ | |
levee.HTTPStatus(200), | |
{}, | |
("Connected: %s\n"):format(connections)}) | |
conn:close() | |
end | |
end) | |
-- TCP Service | |
local err, serve = h.tcp:listen(9000) | |
while true do | |
local err, conn = serve:recv() | |
h:spawn(function() | |
connections = connections + 1 | |
while true do | |
local err = conn:write("hi\n") | |
if err then break end | |
h:sleep(1000) | |
end | |
connections = connections - 1 | |
conn:close() | |
end) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment