mirror of
https://github.com/lunarmodules/luasocket.git
synced 2025-07-13 06:04:31 +02:00
Bug feioso no UDP e possivelmente no TCP também.
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user