comparison samples/echosrvr.lua @ 0:4b915342e2a8

LuaSocket 2.0.2 + CMake build description.
author Eric Wing <ewing . public |-at-| gmail . com>
date Tue, 26 Aug 2008 18:40:01 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4b915342e2a8
1 -----------------------------------------------------------------------------
2 -- UDP sample: echo protocol server
3 -- LuaSocket sample files
4 -- Author: Diego Nehab
5 -- RCS ID: $Id: echosrvr.lua,v 1.12 2005/11/22 08:33:29 diego Exp $
6 -----------------------------------------------------------------------------
7 local socket = require("socket")
8 host = host or "127.0.0.1"
9 port = port or 7
10 if arg then
11 host = arg[1] or host
12 port = arg[2] or port
13 end
14 print("Binding to host '" ..host.. "' and port " ..port.. "...")
15 udp = assert(socket.udp())
16 assert(udp:setsockname(host, port))
17 assert(udp:settimeout(5))
18 ip, port = udp:getsockname()
19 assert(ip, port)
20 print("Waiting packets on " .. ip .. ":" .. port .. "...")
21 while 1 do
22 dgram, ip, port = udp:receivefrom()
23 if dgram then
24 print("Echoing '" .. dgram .. "' to " .. ip .. ":" .. port)
25 udp:sendto(dgram, ip, port)
26 else
27 print(ip)
28 end
29 end