diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-01-25 21:59:39 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-01-25 21:59:39 +0000 |
commit | 7096b8df82eebfe857e0043bc8a853353bd78480 (patch) | |
tree | f5cdc12138e9526896ff5f8fe9e3ffaa0c47fc0c /samples/echosrvr.lua | |
parent | 68f51243b38bf1e32d471e9cc9ddf12a25110e80 (diff) | |
download | luasocket-7096b8df82eebfe857e0043bc8a853353bd78480.tar.gz luasocket-7096b8df82eebfe857e0043bc8a853353bd78480.tar.bz2 luasocket-7096b8df82eebfe857e0043bc8a853353bd78480.zip |
Initial revision
Diffstat (limited to 'samples/echosrvr.lua')
-rw-r--r-- | samples/echosrvr.lua | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/samples/echosrvr.lua b/samples/echosrvr.lua new file mode 100644 index 0000000..fe7da06 --- /dev/null +++ b/samples/echosrvr.lua | |||
@@ -0,0 +1,22 @@ | |||
1 | host = host or "127.0.0.1" | ||
2 | port = port or 7 | ||
3 | if arg then | ||
4 | host = arg[1] or host | ||
5 | port = arg[2] or port | ||
6 | end | ||
7 | print("Binding to host '" ..host.. "' and port " ..port.. "...") | ||
8 | udp, err = udpsocket() | ||
9 | if not udp then print(err) exit() end | ||
10 | err = setsockname(udp, host, port) | ||
11 | if err then print(err) exit() end | ||
12 | timeout(udp, 5) | ||
13 | ip, port = getsockname(udp) | ||
14 | print("Waiting packets on " .. ip .. ":" .. port .. "...") | ||
15 | while 1 do | ||
16 | dgram, ip, port = receivefrom(udp) | ||
17 | if not dgram then print(ip) | ||
18 | else | ||
19 | print("Echoing from " .. ip .. ":" .. port) | ||
20 | sendto(udp, dgram, ip, port) | ||
21 | end | ||
22 | end | ||