This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Kouksi44's profile picture

rednet- receive multiple messages

Started by Kouksi44, 03 October 2014 - 02:47 PM
Kouksi44 #1
Posted 03 October 2014 - 04:47 PM
Maybe this question was already asked here but I didn´t find anything that helps me out.

I am trying to make some kind of network for extended rednet range just to find out if I can do it myself.

But somehow,the the client program has to connect to the server (or check if there´s a server around).

I am doing this by broadcasting a message with a specific protocol and waiting for a response of any server near me.
But when there is more then just one server my program will simply take the first to response.

How can I wait for maybe 1 second and save any response of a server I am getting during this period ?

I thought about this problem for a while now but it seems that I am too dumb to find a solution

It would be greagt if someone could help me :)/>
KingofGamesYami #2
Posted 03 October 2014 - 05:03 PM
Something like this?

local function getServerResponse()
  local id = os.startTimer( 1 )
  local responses = {}
  while true do
    local event = { os.pullEvent() }
    if event[ 1 ] == "rednet_message" then
      responses[ #responses + 1 ] = event
    elseif event[ 1 ] == "timer" and event[ 2 ] == id then
      return responses
    end
  end
end
Kouksi44 #3
Posted 03 October 2014 - 05:27 PM
This is exactly what I need thank you :)/>