04.12.2018, 07:16
Try this:
Code:
function tcp_arcam(data, ip, port)
local sock, res, err, len
sock = require('socket').tcp()
sock:settimeout(1)
res, err = sock:connect(ip, port or 50000)
if res then
-- send data
sock:send(data)
-- receive response
res, err = sock:receive(5)
if type(res) == 'string' and #res == 5 then
len = res:byte(5)
res, err = sock:receive(len + 1)
else
alert('receive failed: ' .. tostring(err))
end
else
alert('connect failed: ' .. tostring(err))
end
sock:close()
return res, err
end