Almost ready to release beta3
This commit is contained in:
parent
a8254e94f8
commit
97b26e0b66
23 changed files with 53 additions and 59 deletions
|
@ -7,7 +7,7 @@ is not supported.
|
|||
listener.lua and talker.lua are about the simplest applications you can
|
||||
write using LuaSocket. Run
|
||||
|
||||
'lua listen.lua' and 'lua talk.lua'
|
||||
'lua listener.lua' and 'lua talker.lua'
|
||||
|
||||
on different terminals. Whatever you type on talk.lua will be
|
||||
printed by listen.lua.
|
||||
|
|
|
@ -12,13 +12,13 @@ if arg then
|
|||
port = arg[2] or port
|
||||
end
|
||||
host = socket.dns.toip(host)
|
||||
udp = socket.try(socket.udp())
|
||||
socket.try(udp:setpeername(host, port))
|
||||
udp = assert(socket.udp())
|
||||
assert(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
|
||||
socket.try(udp:send(line))
|
||||
dgram = socket.try(udp:receive())
|
||||
if not line or line == "" then os.exit() end
|
||||
assert(udp:send(line))
|
||||
dgram = assert(udp:receive())
|
||||
print(dgram)
|
||||
end
|
||||
|
|
|
@ -12,10 +12,11 @@ if arg then
|
|||
port = arg[2] or port
|
||||
end
|
||||
print("Binding to host '" ..host.. "' and port " ..port.. "...")
|
||||
udp = socket.try(socket.udp())
|
||||
socket.try(udp:setsockname(host, port))
|
||||
socket.try(udp:settimeout(5))
|
||||
ip, port = socket.try(udp:getsockname())
|
||||
udp = assert(socket.udp())
|
||||
assert(udp:setsockname(host, port))
|
||||
assert(udp:settimeout(5))
|
||||
ip, port = udp:getsockname()
|
||||
assert(ip, port)
|
||||
print("Waiting packets on " .. ip .. ":" .. port .. "...")
|
||||
while 1 do
|
||||
dgram, ip, port = udp:receivefrom()
|
||||
|
|
|
@ -12,10 +12,11 @@ if arg then
|
|||
port = arg[2] or port
|
||||
end
|
||||
print("Binding to host '" ..host.. "' and port " ..port.. "...")
|
||||
s = socket.try(socket.bind(host, port))
|
||||
i, p = socket.try(s:getsockname())
|
||||
s = assert(socket.bind(host, port))
|
||||
i, p = s:getsockname()
|
||||
assert(i, p)
|
||||
print("Waiting connection from talker on " .. i .. ":" .. p .. "...")
|
||||
c = socket.try(s:accept())
|
||||
c = assert(s:accept())
|
||||
print("Connected. Here is the stuff:")
|
||||
l, e = c:receive()
|
||||
while not e do
|
||||
|
|
|
@ -12,10 +12,10 @@ if arg then
|
|||
port = arg[2] or port
|
||||
end
|
||||
print("Attempting connection to host '" ..host.. "' and port " ..port.. "...")
|
||||
c = socket.try(socket.connect(host, port))
|
||||
c = assert(socket.connect(host, port))
|
||||
print("Connected! Please type stuff (empty line to stop):")
|
||||
l = io.read()
|
||||
while l and l ~= "" and not e do
|
||||
socket.try(c:send(l, "\n"))
|
||||
assert(c:send(l .. "\n"))
|
||||
l = io.read()
|
||||
end
|
||||
|
|
|
@ -14,8 +14,8 @@ if arg then
|
|||
port2 = arg[3] or port2
|
||||
end
|
||||
|
||||
server1 = socket.try(socket.bind(host, port1))
|
||||
server2 = socket.try(socket.bind(host, port2))
|
||||
server1 = assert(socket.bind(host, port1))
|
||||
server2 = assert(socket.bind(host, port2))
|
||||
server1:settimeout(1) -- make sure we don't block in accept
|
||||
server2:settimeout(1)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue