I've been trying to do some basic networking in lua with luasocket.
I have a basic server set up, but I can't figure out how settimeout() works.
Code: Select all
function Server:run()
print("Running.")
self.running = true
while self.running do
if self.client == nil then
print("Waiting for client.")
self.client = self.server: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
Instead, I just get a constant spamming of the error message "Error: timeout" as though the program is not waiting at all.