mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-11-08 14:28:21 +01:00
4919a83d22
on error, return partial result in the end. http.lua rewritten.
30 lines
765 B
Lua
30 lines
765 B
Lua
host = host or "localhost"
|
|
port = port or "8080"
|
|
|
|
server, error = socket.bind(host, port)
|
|
if not server then print("server: " .. tostring(error)) os.exit() end
|
|
ack = "\n"
|
|
while 1 do
|
|
print("server: waiting for client connection...");
|
|
control, error = server:accept()
|
|
assert(control, error)
|
|
-- control:setoption("nodelay", true)
|
|
while 1 do
|
|
command, error = control:receive()
|
|
if error then
|
|
control:close()
|
|
print("server: closing connection...")
|
|
break
|
|
end
|
|
sent, error = control:send(ack)
|
|
if error then
|
|
control:close()
|
|
print("server: closing connection...")
|
|
break
|
|
end
|
|
print(command);
|
|
|
|
(loadstring(command))()
|
|
end
|
|
end
|