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/echoclnt.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/echoclnt.lua')
| -rw-r--r-- | samples/echoclnt.lua | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/samples/echoclnt.lua b/samples/echoclnt.lua index 56bd123..a3d75f3 100644 --- a/samples/echoclnt.lua +++ b/samples/echoclnt.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 "localhost" | 8 | host = host or "localhost" |
| 8 | port = port or 7 | 9 | port = port or 7 |
| 9 | if arg then | 10 | if arg then |
| @@ -11,17 +12,13 @@ if arg then | |||
| 11 | port = arg[2] or port | 12 | port = arg[2] or port |
| 12 | end | 13 | end |
| 13 | host = socket.dns.toip(host) | 14 | host = socket.dns.toip(host) |
| 14 | udp, err = socket.udp() | 15 | udp = socket.try(socket.udp()) |
| 15 | assert(udp, err) | 16 | socket.try(udp:setpeername(host, port)) |
| 16 | ret, err = udp:setpeername(host, port) | 17 | print("Using remote host '" ..host.. "' and port " .. port .. "...") |
| 17 | assert(ret, err) | ||
| 18 | print("Using host '" ..host.. "' and port " .. port .. "...") | ||
| 19 | while 1 do | 18 | while 1 do |
| 20 | line = io.read() | 19 | line = io.read() |
| 21 | if not line then os.exit() end | 20 | if not line then os.exit() end |
| 22 | ret, err = udp:send(line) | 21 | socket.try(udp:send(line)) |
| 23 | if not ret then print(err) os.exit() end | 22 | dgram = socket.try(udp:receive()) |
| 24 | dgram, err = udp:receive() | ||
| 25 | if not dgram then print(err) os.exit() end | ||
| 26 | print(dgram) | 23 | print(dgram) |
| 27 | end | 24 | end |
