Setup management of socket create/close.
[luaevent.git] / luaevent / test / test.lua
blobfd9919db87e890a3c37f04259e54ad7456e1c5b4
1 -- Tests Copas with a simple Echo server
2 --
3 -- Run the test file and the connect to the server by telnet on the used port
4 -- to stop the test just send the command "quit"
6 require"luaevent"
7 require"socket"
8 local function echoHandler(skt)
9 while true do
10 local data,ret = luaevent.receive(skt, 10)
11 if data == "quit" or ret == 'closed' or not data then
12 break
13 end
14 --collectgarbage()
15 if not luaevent.send(skt, data) then return end
16 end
17 if skt then skt:close() end
18 end
20 local server = assert(socket.bind("localhost", 20000))
21 server:settimeout(0)
23 luaevent.addserver(server, echoHandler)
24 luaevent.loop()