Blame samples/listener.lua

Packit b53373
-----------------------------------------------------------------------------
Packit b53373
-- TCP sample: Little program to dump lines received at a given port
Packit b53373
-- LuaSocket sample files
Packit b53373
-- Author: Diego Nehab
Packit b53373
-----------------------------------------------------------------------------
Packit b53373
local socket = require("socket")
Packit b53373
host = host or "*"
Packit b53373
port = port or 8080
Packit b53373
if arg then
Packit b53373
	host = arg[1] or host
Packit b53373
	port = arg[2] or port
Packit b53373
end
Packit b53373
print("Binding to host '" ..host.. "' and port " ..port.. "...")
Packit b53373
s = assert(socket.bind(host, port))
Packit b53373
i, p   = s:getsockname()
Packit b53373
assert(i, p)
Packit b53373
print("Waiting connection from talker on " .. i .. ":" .. p .. "...")
Packit b53373
c = assert(s:accept())
Packit b53373
print("Connected. Here is the stuff:")
Packit b53373
l, e = c:receive()
Packit b53373
while not e do
Packit b53373
	print(l)
Packit b53373
	l, e = c:receive()
Packit b53373
end
Packit b53373
print(e)