mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-26 12:28:21 +01:00
Updated to remove use of global methods. Conforming to
LuaSocket release 1.2.1
This commit is contained in:
parent
29226588da
commit
2c9008772e
12
etc/dict.lua
12
etc/dict.lua
@ -17,13 +17,13 @@ while 1 do
|
|||||||
if w=="=" then
|
if w=="=" then
|
||||||
w=read"*l"
|
w=read"*l"
|
||||||
verbose(">>>",w,"\n")
|
verbose(">>>",w,"\n")
|
||||||
send(s,w,"\r\n")
|
s:send(w,"\r\n")
|
||||||
else
|
else
|
||||||
verbose(">>> looking up `",w,"'\n")
|
verbose(">>> looking up `",w,"'\n")
|
||||||
send(s,"DEFINE wn ",w,"\r\n")
|
s:send("DEFINE wn ",w,"\r\n")
|
||||||
end
|
end
|
||||||
while 1 do
|
while 1 do
|
||||||
local l=receive(s)
|
local l=s:receive()
|
||||||
if l==nil then break end
|
if l==nil then break end
|
||||||
if strfind(l,"^[0-9]") then
|
if strfind(l,"^[0-9]") then
|
||||||
write("<<< ",l,"\n")
|
write("<<< ",l,"\n")
|
||||||
@ -34,6 +34,6 @@ while 1 do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
send(s,"QUIT\r\n")
|
s:send("QUIT\r\n")
|
||||||
verbose("<<< ",receive(s),"\n")
|
verbose("<<< ",s:receive(),"\n")
|
||||||
close(s)
|
s:close()
|
||||||
|
@ -7,15 +7,15 @@ end
|
|||||||
host = toip(host)
|
host = toip(host)
|
||||||
udp, err = udpsocket()
|
udp, err = udpsocket()
|
||||||
if not udp then print(err) exit() end
|
if not udp then print(err) exit() end
|
||||||
err = setpeername(udp, host, port)
|
err = udp:setpeername(host, port)
|
||||||
if err then print(err) exit() end
|
if err then print(err) exit() end
|
||||||
print("Using host '" ..host.. "' and port " ..port.. "...")
|
print("Using host '" ..host.. "' and port " .. port .. "...")
|
||||||
while 1 do
|
while 1 do
|
||||||
line = read()
|
line = read()
|
||||||
if not line then exit() end
|
if not line then exit() end
|
||||||
err = send(udp, line)
|
err = udp:send(line)
|
||||||
if err then print(err) exit() end
|
if err then print(err) exit() end
|
||||||
dgram, err = receive(udp)
|
dgram, err = udp:receive()
|
||||||
if not dgram then print(err) exit() end
|
if not dgram then print(err) exit() end
|
||||||
print(dgram)
|
print(dgram)
|
||||||
end
|
end
|
||||||
|
@ -7,16 +7,16 @@ end
|
|||||||
print("Binding to host '" ..host.. "' and port " ..port.. "...")
|
print("Binding to host '" ..host.. "' and port " ..port.. "...")
|
||||||
udp, err = udpsocket()
|
udp, err = udpsocket()
|
||||||
if not udp then print(err) exit() end
|
if not udp then print(err) exit() end
|
||||||
err = setsockname(udp, host, port)
|
err = udp:setsockname(host, port)
|
||||||
if err then print(err) exit() end
|
if err then print(err) exit() end
|
||||||
timeout(udp, 5)
|
udp:timeout(5)
|
||||||
ip, port = getsockname(udp)
|
ip, port = udp:getsockname()
|
||||||
print("Waiting packets on " .. ip .. ":" .. port .. "...")
|
print("Waiting packets on " .. ip .. ":" .. port .. "...")
|
||||||
while 1 do
|
while 1 do
|
||||||
dgram, ip, port = receivefrom(udp)
|
dgram, ip, port = udp:receivefrom()
|
||||||
if not dgram then print(ip)
|
if not dgram then print(ip)
|
||||||
else
|
else
|
||||||
print("Echoing from " .. ip .. ":" .. port)
|
print("Echoing from " .. ip .. ":" .. port)
|
||||||
sendto(udp, dgram, ip, port)
|
udp:sendto(dgram, ip, port)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user