03.10.2022, 12:56
You can make multiple copies of this script as a resident script with sleep time set to 0. init script should not have any blocking or long-running parts.
Also non-blocking connect should be used and possible errors during receive should be checked:
Also non-blocking connect should be used and possible errors during receive should be checked:
Code:
if not sock then
sock = require('socket').tcp()
sock:settimeout(1)
res, err = sock:connect('192.168.1.100', 2401)
if not res then
log('connect failed', err)
sock:close()
sock = nil
os.sleep(1)
end
end
if sock then
res, err = sock:receive('*l')
if res then
-- parse res
elseif err == 'closed' then
log('connection closed')
sock:close()
sock = nil
end
end