Adjusted a few inconsistencies with the manual.
This commit is contained in:
parent
3099704aff
commit
c51d4acf1c
20 changed files with 412 additions and 156 deletions
|
@ -10,7 +10,7 @@ if arg then
|
|||
host = arg[1] or host
|
||||
port = arg[2] or port
|
||||
end
|
||||
host = socket.toip(host)
|
||||
host = socket.dns.toip(host)
|
||||
udp = socket.udp()
|
||||
print("Using host '" ..host.. "' and port " ..port.. "...")
|
||||
udp:setpeername(host, port)
|
||||
|
|
|
@ -10,17 +10,17 @@ if arg then
|
|||
host = arg[1] or host
|
||||
port = arg[2] or port
|
||||
end
|
||||
host = socket.toip(host)
|
||||
host = socket.dns.toip(host)
|
||||
udp, err = socket.udp()
|
||||
if not udp then print(err) exit() end
|
||||
err = udp:setpeername(host, port)
|
||||
if err then print(err) exit() end
|
||||
assert(udp, err)
|
||||
ret, err = udp:setpeername(host, port)
|
||||
assert(ret, err)
|
||||
print("Using host '" ..host.. "' and port " .. port .. "...")
|
||||
while 1 do
|
||||
line = io.read()
|
||||
if not line then os.exit() end
|
||||
err = udp:send(line)
|
||||
if err then print(err) 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
|
||||
print(dgram)
|
||||
|
|
|
@ -12,11 +12,12 @@ if arg then
|
|||
end
|
||||
print("Binding to host '" ..host.. "' and port " ..port.. "...")
|
||||
udp, err = socket.udp()
|
||||
if not udp then print(err) os.exit() end
|
||||
err = udp:setsockname(host, port)
|
||||
if err then print(err) os.exit() end
|
||||
udp:timeout(5)
|
||||
assert(udp, err)
|
||||
ret, err = udp:setsockname(host, port)
|
||||
assert(ret, err)
|
||||
udp:settimeout(5)
|
||||
ip, port = udp:getsockname()
|
||||
assert(ip, port)
|
||||
print("Waiting packets on " .. ip .. ":" .. port .. "...")
|
||||
while 1 do
|
||||
dgram, ip, port = udp:receivefrom()
|
||||
|
|
|
@ -15,10 +15,10 @@ end
|
|||
|
||||
server1, error = socket.bind(host, port1)
|
||||
assert(server1, error)
|
||||
server1:timeout(1) -- make sure we don't block in accept
|
||||
server1:settimeout(1) -- make sure we don't block in accept
|
||||
server2, error = socket.bind(host, port2)
|
||||
assert(server2, error)
|
||||
server2:timeout(1) -- make sure we don't block in accept
|
||||
server2:settimeout(1) -- make sure we don't block in accept
|
||||
|
||||
io.write("Servers bound\n")
|
||||
|
||||
|
@ -55,7 +55,7 @@ while 1 do
|
|||
io.write("Waiting for clients\n")
|
||||
local new = input:accept()
|
||||
if new then
|
||||
new:timeout(1)
|
||||
new:settimeout(1)
|
||||
io.write("Inserting client in set\n")
|
||||
set:insert(new)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue