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