Posted 30 December 2012 - 11:58 AM
Hi, I was wondering if anyone could help me out. I was playing around with red net and I realized there was no built in way to detect which devices are in range, making it hard to work with red net to send commands, messages etc. between computers.
I soon came up with a simple system of sending a ping message from one computer and having the receiving computers send a ping back when they received it. Here's what I came up with so far:
the client "Operating system" :
ping script:
When I run ping the first time it works fine and returns the id's of any pc running JoeNet in range. But the second time I run it, It ignores the ping requests.
What I think is happening is the returnPing() function is returnign a value, thus stopping the parallel from running. But I'm not sure.
If anyone has help or Suggestions I'd appreciate it :)/>
I soon came up with a simple system of sending a ping message from one computer and having the receiving computers send a ping back when they received it. Here's what I came up with so far:
the client "Operating system" :
function returnPing()
event, id, text = os.pullEvent()
if event == "rednet_message" then
if text == "JOENET PING" then
rednet.send(id, "JOENET PING")
print("ping received")
end
end
end
function sendMessage()
print("Enter text to broadcast:")
local message = io.read()
rednet.broadcast(message)
end
while true do
parallel.waitForAll(sendMessage, returnPing)
end
ping script:
local replys = {}
local timerOn = true
function addToArray(id)
replys[#replys + 1] = id
end
function printReplys()
for i=1,#replys do
print(replys[i])
end
end
function ping()
rednet.broadcast("JOENET PING")
--print("ping sent to all computers in range, wait for responce")
end
ping()
os.startTimer(1)
while timerOn do
event, id, param2 = os.pullEvent()
if event == "rednet_message" then
if param2 == "JOENET PING" then
addToArray(tostring(id))
end
end
if event == "timer" then
timerOn = false
end
end
printReplys()
When I run ping the first time it works fine and returns the id's of any pc running JoeNet in range. But the second time I run it, It ignores the ping requests.
What I think is happening is the returnPing() function is returnign a value, thus stopping the parallel from running. But I'm not sure.
If anyone has help or Suggestions I'd appreciate it :)/>