From c98dc991998c724a3f6a1fdd90b5d1d8a80e3af3 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Fri, 28 May 2004 07:24:43 +0000 Subject: Bug feioso no UDP e possivelmente no TCP também. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- samples/cddb.lua | 3 +++ samples/daytimeclnt.lua | 1 + samples/echoclnt.lua | 15 ++++++--------- samples/echosrvr.lua | 21 ++++++++++----------- 4 files changed, 20 insertions(+), 20 deletions(-) (limited to 'samples') diff --git a/samples/cddb.lua b/samples/cddb.lua index 0ed7c71..09309e8 100644 --- a/samples/cddb.lua +++ b/samples/cddb.lua @@ -1,3 +1,6 @@ +require"luasocket" +require"http" + if not arg or not arg[1] or not arg[2] then print("luasocket cddb.lua []") os.exit(1) diff --git a/samples/daytimeclnt.lua b/samples/daytimeclnt.lua index 63f4017..ee7f652 100644 --- a/samples/daytimeclnt.lua +++ b/samples/daytimeclnt.lua @@ -4,6 +4,7 @@ -- Author: Diego Nehab -- RCS ID: $Id$ ----------------------------------------------------------------------------- +require"luasocket" host = host or "127.0.0.1" port = port or 13 if arg then 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 @@ -- Author: Diego Nehab -- RCS ID: $Id$ ----------------------------------------------------------------------------- +require"luasocket" host = host or "localhost" port = port or 7 if arg then @@ -11,17 +12,13 @@ if arg then port = arg[2] or port end host = socket.dns.toip(host) -udp, err = socket.udp() -assert(udp, err) -ret, err = udp:setpeername(host, port) -assert(ret, err) -print("Using host '" ..host.. "' and port " .. port .. "...") +udp = socket.try(socket.udp()) +socket.try(udp:setpeername(host, port)) +print("Using remote host '" ..host.. "' and port " .. port .. "...") while 1 do line = io.read() if not line then os.exit() end - ret, err = udp:send(line) - if not ret then print(err) os.exit() end - dgram, err = udp:receive() - if not dgram then print(err) os.exit() end + socket.try(udp:send(line)) + dgram = socket.try(udp:receive()) print(dgram) end 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 @@ -- Author: Diego Nehab -- RCS ID: $Id$ ----------------------------------------------------------------------------- +require"luasocket" host = host or "127.0.0.1" port = port or 7 if arg then @@ -11,19 +12,17 @@ if arg then port = arg[2] or port end print("Binding to host '" ..host.. "' and port " ..port.. "...") -udp, err = socket.udp() -assert(udp, err) -ret, err = udp:setsockname(host, port) -assert(ret, err) -udp:settimeout(5) -ip, port = udp:getsockname() -assert(ip, port) +udp = socket.try(socket.udp()) +socket.try(udp:setsockname(host, port)) +socket.try(udp:settimeout(5)) +ip, port = socket.try(udp:getsockname()) print("Waiting packets on " .. ip .. ":" .. port .. "...") while 1 do dgram, ip, port = udp:receivefrom() - if not dgram then print(ip) - else - print("Echoing from " .. ip .. ":" .. port) + if dgram then + print("Echoing '" .. dgram .. "' to " .. ip .. ":" .. port) udp:sendto(dgram, ip, port) - end + else + print(ip) + end end -- cgit v1.2.3-55-g6feb