singe/thirdparty/copas/misc/echoserver.lua

24 lines
577 B
Lua

-- 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()