diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-05-28 07:24:43 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-05-28 07:24:43 +0000 |
commit | c98dc991998c724a3f6a1fdd90b5d1d8a80e3af3 (patch) | |
tree | 8d8b8aa856d8a3e822121d0915a63b8244f471bb /samples/echosrvr.lua | |
parent | 9297b074d53a00e1149250e0bbfa0871dcc5558f (diff) | |
download | luasocket-c98dc991998c724a3f6a1fdd90b5d1d8a80e3af3.tar.gz luasocket-c98dc991998c724a3f6a1fdd90b5d1d8a80e3af3.tar.bz2 luasocket-c98dc991998c724a3f6a1fdd90b5d1d8a80e3af3.zip |
Bug feioso no UDP e possivelmente no TCP também.
Diffstat (limited to 'samples/echosrvr.lua')
-rw-r--r-- | samples/echosrvr.lua | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/samples/echosrvr.lua b/samples/echosrvr.lua index a7ed03c..9d99506 100644 --- a/samples/echosrvr.lua +++ b/samples/echosrvr.lua | |||
@@ -4,6 +4,7 @@ | |||
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- RCS ID: $Id$ | 5 | -- RCS ID: $Id$ |
6 | ----------------------------------------------------------------------------- | 6 | ----------------------------------------------------------------------------- |
7 | require"luasocket" | ||
7 | host = host or "127.0.0.1" | 8 | host = host or "127.0.0.1" |
8 | port = port or 7 | 9 | port = port or 7 |
9 | if arg then | 10 | if arg then |
@@ -11,19 +12,17 @@ if arg then | |||
11 | port = arg[2] or port | 12 | port = arg[2] or port |
12 | end | 13 | end |
13 | print("Binding to host '" ..host.. "' and port " ..port.. "...") | 14 | print("Binding to host '" ..host.. "' and port " ..port.. "...") |
14 | udp, err = socket.udp() | 15 | udp = socket.try(socket.udp()) |
15 | assert(udp, err) | 16 | socket.try(udp:setsockname(host, port)) |
16 | ret, err = udp:setsockname(host, port) | 17 | socket.try(udp:settimeout(5)) |
17 | assert(ret, err) | 18 | ip, port = socket.try(udp:getsockname()) |
18 | udp:settimeout(5) | ||
19 | ip, port = udp:getsockname() | ||
20 | assert(ip, port) | ||
21 | print("Waiting packets on " .. ip .. ":" .. port .. "...") | 19 | print("Waiting packets on " .. ip .. ":" .. port .. "...") |
22 | while 1 do | 20 | while 1 do |
23 | dgram, ip, port = udp:receivefrom() | 21 | dgram, ip, port = udp:receivefrom() |
24 | if not dgram then print(ip) | 22 | if dgram then |
25 | else | 23 | print("Echoing '" .. dgram .. "' to " .. ip .. ":" .. port) |
26 | print("Echoing from " .. ip .. ":" .. port) | ||
27 | udp:sendto(dgram, ip, port) | 24 | udp:sendto(dgram, ip, port) |
28 | end | 25 | else |
26 | print(ip) | ||
27 | end | ||
29 | end | 28 | end |