File: testsrvr.lua

package info (click to toggle)
luasocket 2.0-alpha-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 452 kB
  • ctags: 437
  • sloc: ansic: 2,015; makefile: 107
file content (26 lines) | stat: -rw-r--r-- 714 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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 = server:accept()
    -- 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
        (loadstring(command))()
    end
end