Echo server: Difference between revisions
→{{header|Lua}}: I fixed error with require("socket"); made code more clear.
m (Write a message when a connection is accepted.) |
(→{{header|Lua}}: I fixed error with require("socket"); made code more clear.) |
||
Line 1,526:
=={{header|Lua}}==
{{works with|Lua|5.3}}
{{libheader|LuaSocket}}
This implementation doesn't rely on coroutines because they're an additional (often confusing) notion that could make the example needlessly hard to understand. Instead it uses a table of not-quite-non-blocking socket client objects (they block for
<lang Lua>local socket=require("socket")
function checkOn (client)
Line 1,539 ⟶ 1,540:
print(tostring(client) .. " " .. err)
client:close()
return
end
return
end
local delay
local connections = {} -- an array of connections
local newClient
local server = assert(socket.bind("*", 12321))
server:settimeout(delay)
▲while 1 do
repeat
newClient = server:accept()
for
if checkOn(
end
until newClient
newClient:settimeout(delay)
print(tostring(newClient) .. " connected")
table.insert(
end</lang>
Without the
=={{header|Nim}}==
|