1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
-- Tests Copas with a simple Echo server
--
-- Run the test file and the connect to the server using telnet on the used port.
-- The server should be able to echo any input, to stop the test just send the command "quit"
local copas = require("copas")
local socket = require("socket")
local function echoHandler(skt)
skt = copas.wrap(skt)
while true do
local data = skt:receive()
if not data or data == "quit" then
break
end
skt:send(data)
end
end
local server = socket.bind("localhost", 20000)
copas.addserver(server, echoHandler)
copas.loop()
|