I have the following code:
function Server:run()
print("Running.")
self.running = true
while self.running do
if self.client == nil then
self.client = self.socket:accept()
print("Client connected.")
self.client:settimeout(10)
end
local line, err = self.client:receive()
if err then
print("Error: " .. err)
elseif line == "quit" then
print("Quitting.")
self.client:close()
self.running = false
else
print("Received: " .. line)
end
end
self:terminate()
end
I expect that when self.client:receive() is called, the server will wait for 10 seconds or until it has a message, and then continue on its way.
However, this is not the behaviour I experience. The server instead instantly generates a timeout error no matter what value the timeout is set to, and doesn't wait at all for a message from the client.
I suspect I've misunderstood something. Any insight would be appreicated. Thanks.
Full code here:
Server: http://pastie.org/9659701
main: http://pastie.org/9659703