Bug feioso no UDP e possivelmente no TCP também.

This commit is contained in:
Diego Nehab 2004-05-28 07:24:43 +00:00
parent 9297b074d5
commit c98dc99199
14 changed files with 59 additions and 50 deletions

View file

@ -1,3 +1,6 @@
require"luasocket"
require"http"
if not arg or not arg[1] or not arg[2] then
print("luasocket cddb.lua <category> <disc-id> [<server>]")
os.exit(1)

View file

@ -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

View file

@ -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

View file

@ -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