mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-26 04:28:20 +01:00
Connection closed detection was improved. Client numbers are now tracked
and sent along with broadcasted line.
This commit is contained in:
parent
3f52ed5c53
commit
98a7e91de5
@ -28,34 +28,42 @@ server2:timeout(1)
|
|||||||
server2.is_server = 1
|
server2.is_server = 1
|
||||||
|
|
||||||
set = {server1, server2}
|
set = {server1, server2}
|
||||||
|
number = 1
|
||||||
|
|
||||||
while 1 do
|
while 1 do
|
||||||
local r, s, e, l
|
local r, s, e, l, n
|
||||||
r, _, e = select(set, nil)
|
r, _, e = select(set, nil)
|
||||||
for i, v in r do
|
for i, v in r do
|
||||||
if v.is_server then
|
if v.is_server then
|
||||||
s = v:accept()
|
s = v:accept()
|
||||||
if s then
|
if s then
|
||||||
s:timeout(1)
|
s:timeout(1)
|
||||||
|
s.number = number
|
||||||
|
number = number + 1
|
||||||
set_add(set, s)
|
set_add(set, s)
|
||||||
write("Added new client. ", getn(set)-2, " total.\n")
|
write("Added client number ", s.number, ". ",
|
||||||
|
getn(set)-2, " total.\n")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
l, e = v:receive()
|
l, e = v:receive()
|
||||||
|
n = v.number
|
||||||
if e then
|
if e then
|
||||||
v:close()
|
v:close()
|
||||||
set_remove(set, v)
|
set_remove(set, v)
|
||||||
write("Removed client. ", getn(set)-2, " total.\n")
|
write("Removed client number ", n, ". ",
|
||||||
end
|
getn(set)-2, " total.\n")
|
||||||
write("Broadcasting line '", tostring(l), "'.\n")
|
|
||||||
_, s, e = select(nil, set, 1)
|
|
||||||
if not e then
|
|
||||||
for i,v in s do
|
|
||||||
v:send(l, "\r\n")
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
write("No one ready to listen!!!\n")
|
write("Broadcasting line '", tostring(n), "> ",
|
||||||
end
|
tostring(l), "'.\n")
|
||||||
|
_, s, e = select(nil, set, 1)
|
||||||
|
if not e then
|
||||||
|
for i,v in s do
|
||||||
|
v:send(tostring(n), "> ", l, "\r\n")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
write("No one ready to listen!!!\n")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user