diff options
Diffstat (limited to 'test/testsrvr.lua')
-rw-r--r-- | test/testsrvr.lua | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/test/testsrvr.lua b/test/testsrvr.lua index 969f95b..23e3850 100644 --- a/test/testsrvr.lua +++ b/test/testsrvr.lua | |||
@@ -1,29 +1,14 @@ | |||
1 | socket = require"socket" | 1 | socket = require("socket"); |
2 | 2 | host = host or "localhost"; | |
3 | host = host or "localhost" | 3 | port = port or "8080"; |
4 | port = port or "8080" | 4 | server = assert(socket.bind(host, port)); |
5 | 5 | ack = "\n"; | |
6 | server, error = socket.bind(host, port) | ||
7 | if not server then print("server: " .. tostring(error)) os.exit() end | ||
8 | ack = "\n" | ||
9 | while 1 do | 6 | while 1 do |
10 | print("server: waiting for client connection..."); | 7 | print("server: waiting for client connection..."); |
11 | control, error = server:accept() | 8 | control = assert(server:accept()); |
12 | assert(control, error) | ||
13 | -- control:setoption("nodelay", true) | ||
14 | while 1 do | 9 | while 1 do |
15 | command, error = control:receive() | 10 | command = assert(control:receive()); |
16 | if error then | 11 | assert(control:send(ack)); |
17 | control:close() | 12 | (loadstring(command))(); |
18 | print("server: closing connection...") | ||
19 | break | ||
20 | end | ||
21 | sent, error = control:send(ack) | ||
22 | if error then | ||
23 | control:close() | ||
24 | print("server: closing connection...") | ||
25 | break | ||
26 | end | ||
27 | (loadstring(command))() | ||
28 | end | 13 | end |
29 | end | 14 | end |