2004-05-28 07:24:43 +00:00
|
|
|
require "luasocket"
|
|
|
|
|
2003-03-28 21:08:50 +00:00
|
|
|
host = host or "localhost"
|
|
|
|
port = port or "8080"
|
2001-01-25 22:00:18 +00:00
|
|
|
|
2003-03-28 21:08:50 +00:00
|
|
|
server, error = socket.bind(host, port)
|
2002-12-03 07:20:34 +00:00
|
|
|
if not server then print("server: " .. tostring(error)) os.exit() end
|
2003-06-26 18:47:49 +00:00
|
|
|
ack = "\n"
|
2001-01-25 22:00:18 +00:00
|
|
|
while 1 do
|
2002-07-08 21:56:01 +00:00
|
|
|
print("server: waiting for client connection...");
|
2004-01-21 20:16:48 +00:00
|
|
|
control, error = server:accept()
|
|
|
|
assert(control, error)
|
2003-06-26 21:14:17 +00:00
|
|
|
-- control:setoption("nodelay", true)
|
2002-07-08 21:56:01 +00:00
|
|
|
while 1 do
|
|
|
|
command, error = control:receive()
|
2004-05-28 07:38:12 +00:00
|
|
|
print(error)
|
2002-07-08 21:56:01 +00:00
|
|
|
if error then
|
|
|
|
control:close()
|
|
|
|
print("server: closing connection...")
|
|
|
|
break
|
|
|
|
end
|
2003-06-26 18:47:49 +00:00
|
|
|
sent, error = control:send(ack)
|
2002-07-08 21:56:01 +00:00
|
|
|
if error then
|
|
|
|
control:close()
|
|
|
|
print("server: closing connection...")
|
|
|
|
break
|
|
|
|
end
|
2004-05-28 07:38:12 +00:00
|
|
|
print(command);
|
2002-12-03 07:20:34 +00:00
|
|
|
(loadstring(command))()
|
2002-07-08 21:56:01 +00:00
|
|
|
end
|
2001-01-25 22:00:18 +00:00
|
|
|
end
|