summaryrefslogtreecommitdiffstats
path: root/ncat/scripts/echo.lua
blob: 3bfea90d0d2193ed2b0a52c1045b58e2771d8888 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
--Emulates the RFC 862 echo service, behaving like Unix's "cat" tool.

while true do

  --We're reading in 1-byte chunks because calls like io.stdin:read(512) would
  --wait for full 512 bytes of data before continuing.
  data = io.stdin:read(1)

  if data == nil then
    break
  end

  io.stdout:write(data)
  io.stdout:flush()

end