Trying to write a lua server...
Posted: Fri Oct 17, 2014 5:41 pm
Hi! This question isn't specific to LOVE, but I'm not sure where else to look.
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.
I expect the program to get to self.client:receive() and then wait there until it either gets a message from the client or times out after 10 seconds. However, this is not the behaviour I experience.
Instead, I just get a constant spamming of the error message "Error: timeout" as though the program is not waiting at all.
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.