2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -0,0 +1,31 @@
require("socket")
function checkOn (client)
local line, err = client:receive()
if line then
print(tostring(client) .. " said " .. line)
client:send(line .. "\n")
end
if err and err ~= "timeout" then
print(tostring(client) .. " " .. err)
client:close()
return err
end
return nil
end
local delay, clients, newClient = 10^-6, {}
local server = assert(socket.bind("*", 12321))
server:settimeout(delay)
print("Server started")
while 1 do
repeat
newClient = server:accept()
for k, v in pairs(clients) do
if checkOn(v) then table.remove(clients, k) end
end
until newClient
newClient:settimeout(delay)
print(tostring(newClient) .. " connected")
table.insert(clients, newClient)
end