Thank you for the report. The example was not updated since a few versions of LuaRT.
Here is a more updated example to use multiple connected clients on a server :
-- Multi-connection Server example
local net = require "net"
-- create the server listening Socket
local server = net.Socket("127.0.0.1", 5000)
-- array of clients Sockets
local sockets = {server}
server.disconnected = false
if server:bind() then
print("Server running on 127.0.0.1:5000")
else
error("Network error : cannot create the server Socket")
end
while true do
if net.select(sockets) == false then
error("Network error : "..net.error)
break
end
local alive_sockets = {}
for client in each(sockets) do
-- check for readability
if client.canread then
if client == server then
if server.canread then
-- check for new connection
local newclient = server:accept()
print(newclient.ip.." has connected")
sockets[#sockets+1] = newclient
end
else
local data = client:recv()
if data == false then
print(client.ip.." has disconnected")
client.disconnected = true
else
print(client.ip..": "..tostring(data))
end
end
end
-- check for error
if client.failed then
if client == server then
error("fatal network error with server")
else
print(client.ip.." has encountered a fatal network error")
client.disconnected = true
end
end
if not client.disconnected then
alive_sockets[#alive_sockets+1] = client
end
end
-- keep only connected clients
sockets = alive_sockets
end