File: echoserver.lua

package info (click to toggle)
lua-copas 4.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 700 kB
  • sloc: makefile: 62; sh: 43
file content (24 lines) | stat: -rw-r--r-- 577 bytes parent folder | download
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()