(01.06.2016, 09:55)admin Wrote: You should store your table as a storage variable, not every client a separate variable:
Code:t = {}
-- insert values into t
...
-- save to storage
storage.set('clients', t)
You should also check for disconnected clients, otherwise your table will be growing forever which will cause issues in the future. You can also use IP address as table key, so you can set and remove items without having to iterate through the table:
Code:t[ ip1 ] = true -- client connected
t[ ip2 ] = nil -- client disconnected
Thank you for your solution :
I tried it another way, but I will try your solution too.
So I iterate through storage and if I find nil value (storage.set(i)) and not same IP before nil, I store next IP address on that position.
Then when client connection is needed, I send data via created socket like this:
Code:
.
.
.
for i=1,50 do
myIP = storage.get(i);
if myIP == nil then
break
end
else
local host, port = myIP, 10207
local socket = require("socket")
local tcp = assert(socket.tcp())
tcp:connect(host, port);
tcp:send(data)
--log(event)
end
tcp:close();
.
.
.
Think this may work :