I\'m trying to read some (binary) data from a lua socket, but the above code do not terminate the repeat-loop. How can i know that the end of stream has reached ?
Ok, i have found this solution
client = require("socket")
client = socket.connect("www.google.com",80)
client:send("GET / HTTP/1.1\n\n")
client:settimeout(1)
repeat
print "read"
line,err,rest = client:receive(512)
print "read done"
if line then print(line) end
if rest then print(rest) end
until err
print "all done"
The drawback is the settimeout, because the request will take at least 1 second and any network delay more than 1 sec will result in an error.