* Completed mostly working version
[luaevent.git] / luaevent / test / test.lua
blobf7a44da57c51575f507502a6e532df2feea4166b
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' then
12 break
13 end
14 --collectgarbage()
15 luaevent.send(skt, data)
16 end
17 end
19 local server = assert(socket.bind("localhost", 20000))
20 server:settimeout(0)
22 luaevent.addserver(server, echoHandler)
23 luaevent.loop()