~reviczky/luatex/luatex-svn

« back to all changes in this revision

Viewing changes to source/texk/web2c/luatexdir/luasocket/samples/listener.lua

  • Committer: Adam Reviczky
  • Date: 2015-03-29 18:56:26 UTC
  • Revision ID: adam.reviczky@kclalumni.net-20150329185626-7j7tmwyfpa69lqwo
Revision 5213

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-----------------------------------------------------------------------------
 
2
-- TCP sample: Little program to dump lines received at a given port
 
3
-- LuaSocket sample files
 
4
-- Author: Diego Nehab
 
5
-----------------------------------------------------------------------------
 
6
local socket = require("socket")
 
7
host = host or "*"
 
8
port = port or 8080
 
9
if arg then
 
10
        host = arg[1] or host
 
11
        port = arg[2] or port
 
12
end
 
13
print("Binding to host '" ..host.. "' and port " ..port.. "...")
 
14
s = assert(socket.bind(host, port))
 
15
i, p   = s:getsockname()
 
16
assert(i, p)
 
17
print("Waiting connection from talker on " .. i .. ":" .. p .. "...")
 
18
c = assert(s:accept())
 
19
print("Connected. Here is the stuff:")
 
20
l, e = c:receive()
 
21
while not e do
 
22
        print(l)
 
23
        l, e = c:receive()
 
24
end
 
25
print(e)