aboutsummaryrefslogtreecommitdiff
path: root/test/testsrvr.lua
blob: 141c058793eaff7884620227f373b6d9c695e9da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
while 1 do
    print("server: waiting for client connection...");
    control = server:accept()
    while 1 do 
        command, error = control:receive()
        if error then
            control:close()
            print("server: closing connection...")
            break
        end
        error = control:send("\n")
        if error then
            control:close()
            print("server: closing connection...")
            break
        end
        (loadstring(command))()
    end
end