Last active
May 6, 2016 11:06
-
-
Save cablehead/dbf6f73c677f138097ad795714551868 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 d = levee.d | |
| local h = levee.Hub() | |
| local K1 = ("."):rep(1024) | |
| local err, serve = h.stream:listen() | |
| local err, addr = serve:addr() | |
| local i = 0 | |
| h:spawn(function() | |
| for conn in serve do | |
| h:spawn(function() | |
| local buf = d.Buffer(4096) | |
| while true do | |
| conn:readinto(buf) | |
| conn:write(buf:value()) | |
| buf:trim() | |
| i = i + 1 | |
| end | |
| end) | |
| end | |
| end) | |
| for __ = 1, 10 do | |
| h:spawn(function() | |
| local err, c = h.stream:connect(addr:port()) | |
| local buf = d.Buffer(4096) | |
| while true do | |
| c:write(K1) | |
| c:readinto(buf) | |
| assert(#buf == 1024) | |
| buf:trim() | |
| end | |
| end) | |
| end | |
| while true do | |
| h:sleep(1000) | |
| print(i) | |
| i = 0 | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment