This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Store addresses in database
#5
(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 :Smile
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 :Smile
Reply


Messages In This Thread
Store addresses in database - by hrebik - 01.06.2016, 09:15
RE: Store addresses in database - by admin - 01.06.2016, 09:20
RE: Store addresses in database - by hrebik - 01.06.2016, 09:31
RE: Store addresses in database - by admin - 01.06.2016, 09:55
RE: Store addresses in database - by hrebik - 01.06.2016, 10:05
RE: Store addresses in database - by admin - 01.06.2016, 11:22
RE: Store addresses in database - by admin - 03.08.2016, 06:24

Forum Jump: