I'll just begin at the beginning:
I'm working on something like a FTP for CC and when I came to testing, I ran into a bug, even though on one computer there was a rednet host the other computer returned nil when running redent.lookup. But the strange thing about this bug is, that on the first try rednet.lookup returns the id of the other computer. I can only fix rednet.lookup by rebooting the computer which is the rednet host...
Can somebody help me?
Original code
rednet.lookup returning nil
Started by Chickenbreadlp, Jun 03 2016 10:03 PM
5 replies to this topic
#1
Posted 03 June 2016 - 10:03 PM
#2
Posted 03 June 2016 - 10:38 PM
rednet.host shouldn't be called in a loop. However, short of calling rednet.unhost, it should work.
Edit: Noticed checkModem is unnecisarily lengthy, so I re-wrote it:
Edit: Noticed checkModem is unnecisarily lengthy, so I re-wrote it:
local function checkModem()
if rednet.isOpen() then
return true
end
for _, side in ipairs( rs.getSides() ) do
if peripheral.isPresent( side ) and peripheral.getType( side ) == "modem" then
rednet.open( side )
return true
end
end
return false
end
Edited by KingofGamesYami, 03 June 2016 - 10:45 PM.
#3
Posted 04 June 2016 - 12:39 AM
Other than the "constantly calling rednet.host()" thing (which is redundant, but shouldn't cause problems), the only bit of related weirdness I'm seeing is when a "change hostname" command comes through. You never update the value of "runningHost".
#4
Posted 04 June 2016 - 06:47 AM
Bomb Bloke, on 04 June 2016 - 12:39 AM, said:
Other than the "constantly calling rednet.host()" thing (which is redundant, but shouldn't cause problems), the only bit of related weirdness I'm seeing is when a "change hostname" command comes through. You never update the value of "runningHost".
KingofGamesYami, on 03 June 2016 - 10:38 PM, said:
rednet.host shouldn't be called in a loop. However, short of calling rednet.unhost, it should work.
Edit: Noticed checkModem is unnecisarily lengthy, so I re-wrote it:
Edit: Noticed checkModem is unnecisarily lengthy, so I re-wrote it:
local function checkModem() if rednet.isOpen() then return true end for _, side in ipairs( rs.getSides() ) do if peripheral.isPresent( side ) and peripheral.getType( side ) == "modem" then rednet.open( side ) return true end end return false end
EDIT
I tried everything I could imagine, what the problem could be caused by, and nothing worked. I just don't understand this, because if I run the code line by line in the lua program, it works.
Edited by Chickenbreadlp, 04 June 2016 - 11:49 AM.
#5
Posted 04 June 2016 - 12:25 PM
Ah, I think I see the problem.
Rednet works by sending specially formatted messages through modems, which destination systems receive as "modem_message" events in their event queue (same as if you transmit directly through modems, without using rednet at all). When a given system boots, a special function called rednet.run() is started in parallel with the shell. One of its jobs is to look for modem_message events, and if it finds they were transmitted via rednet.send(), it queues corresponding rednet_message events (which you can either pull directly, or via rednet.receive()). It's also rednet.run() which responds to lookup requests.
ComputerCraft 1.6 added a "repeat" script to each system, which waits for incoming rednet messages and re-sends them through all available modems. The purpose of this is to make it easier to extend the range of networks - these days, with a single computer running that script through an Ender Modem, you've got pretty much the whole Minecraft server covered.
The introduction of this script created a bit of a problem in that it became possible for multiple modem_message events to be received for each message sent via rednet. To counter this, Dan added an extra bit of data to each modem_message associated with rednet - a random number. If two modem_messages with the same random number are received within half a minute, rednet.run() will not create a corresponding rednet_message, assuming them to be duplicate copies.
The odds of erroneous collisions are pretty low under normal circumstances, but your "unfoldkey" functions complicate matters by messing with the random number seed. More specifically, they keep resetting it back to a particular static value, which makes the odds of rednet collisions "near certain"!
Change these lines:
... so that the seed is a bit more unpredictable:
math.random() isn't suitable as a seed in this instance because you've just set a seed of "keyhash" (which is the same every time - you read it from a file) and then rolled 32 values. The 33rd value, the one you use to set the new seed, is always going to be the same. The system clock is nearly certain to be different every time you check it, however.
The thing I'm scratching my head over is that if this is the problem - and I can't really see any other alternatives - it'd be the seed of the client system at fault, not the seed of the server. Hrm. Do systems share seeds? Might have to look into that one... Maybe you're simply running similar code on the client system...?
Rednet works by sending specially formatted messages through modems, which destination systems receive as "modem_message" events in their event queue (same as if you transmit directly through modems, without using rednet at all). When a given system boots, a special function called rednet.run() is started in parallel with the shell. One of its jobs is to look for modem_message events, and if it finds they were transmitted via rednet.send(), it queues corresponding rednet_message events (which you can either pull directly, or via rednet.receive()). It's also rednet.run() which responds to lookup requests.
ComputerCraft 1.6 added a "repeat" script to each system, which waits for incoming rednet messages and re-sends them through all available modems. The purpose of this is to make it easier to extend the range of networks - these days, with a single computer running that script through an Ender Modem, you've got pretty much the whole Minecraft server covered.
The introduction of this script created a bit of a problem in that it became possible for multiple modem_message events to be received for each message sent via rednet. To counter this, Dan added an extra bit of data to each modem_message associated with rednet - a random number. If two modem_messages with the same random number are received within half a minute, rednet.run() will not create a corresponding rednet_message, assuming them to be duplicate copies.
The odds of erroneous collisions are pretty low under normal circumstances, but your "unfoldkey" functions complicate matters by messing with the random number seed. More specifically, they keep resetting it back to a particular static value, which makes the odds of rednet collisions "near certain"!
Change these lines:
math.randomseed(math.random())
... so that the seed is a bit more unpredictable:
math.randomseed(os.clock())
math.random() isn't suitable as a seed in this instance because you've just set a seed of "keyhash" (which is the same every time - you read it from a file) and then rolled 32 values. The 33rd value, the one you use to set the new seed, is always going to be the same. The system clock is nearly certain to be different every time you check it, however.
The thing I'm scratching my head over is that if this is the problem - and I can't really see any other alternatives - it'd be the seed of the client system at fault, not the seed of the server. Hrm. Do systems share seeds? Might have to look into that one... Maybe you're simply running similar code on the client system...?
#6
Posted 04 June 2016 - 05:09 PM
Bomb Bloke, on 04 June 2016 - 12:25 PM, said:
Ah, I think I see the problem.
Rednet works by sending specially formatted messages through modems, which destination systems receive as "modem_message" events in their event queue (same as if you transmit directly through modems, without using rednet at all). When a given system boots, a special function called rednet.run() is started in parallel with the shell. One of its jobs is to look for modem_message events, and if it finds they were transmitted via rednet.send(), it queues corresponding rednet_message events (which you can either pull directly, or via rednet.receive()). It's also rednet.run() which responds to lookup requests.
ComputerCraft 1.6 added a "repeat" script to each system, which waits for incoming rednet messages and re-sends them through all available modems. The purpose of this is to make it easier to extend the range of networks - these days, with a single computer running that script through an Ender Modem, you've got pretty much the whole Minecraft server covered.
The introduction of this script created a bit of a problem in that it became possible for multiple modem_message events to be received for each message sent via rednet. To counter this, Dan added an extra bit of data to each modem_message associated with rednet - a random number. If two modem_messages with the same random number are received within half a minute, rednet.run() will not create a corresponding rednet_message, assuming them to be duplicate copies.
The odds of erroneous collisions are pretty low under normal circumstances, but your "unfoldkey" functions complicate matters by messing with the random number seed. More specifically, they keep resetting it back to a particular static value, which makes the odds of rednet collisions "near certain"!
Change these lines:
... so that the seed is a bit more unpredictable:
math.random() isn't suitable as a seed in this instance because you've just set a seed of "keyhash" (which is the same every time - you read it from a file) and then rolled 32 values. The 33rd value, the one you use to set the new seed, is always going to be the same. The system clock is nearly certain to be different every time you check it, however.
The thing I'm scratching my head over is that if this is the problem - and I can't really see any other alternatives - it'd be the seed of the client system at fault, not the seed of the server. Hrm. Do systems share seeds? Might have to look into that one... Maybe you're simply running similar code on the client system...?
Rednet works by sending specially formatted messages through modems, which destination systems receive as "modem_message" events in their event queue (same as if you transmit directly through modems, without using rednet at all). When a given system boots, a special function called rednet.run() is started in parallel with the shell. One of its jobs is to look for modem_message events, and if it finds they were transmitted via rednet.send(), it queues corresponding rednet_message events (which you can either pull directly, or via rednet.receive()). It's also rednet.run() which responds to lookup requests.
ComputerCraft 1.6 added a "repeat" script to each system, which waits for incoming rednet messages and re-sends them through all available modems. The purpose of this is to make it easier to extend the range of networks - these days, with a single computer running that script through an Ender Modem, you've got pretty much the whole Minecraft server covered.
The introduction of this script created a bit of a problem in that it became possible for multiple modem_message events to be received for each message sent via rednet. To counter this, Dan added an extra bit of data to each modem_message associated with rednet - a random number. If two modem_messages with the same random number are received within half a minute, rednet.run() will not create a corresponding rednet_message, assuming them to be duplicate copies.
The odds of erroneous collisions are pretty low under normal circumstances, but your "unfoldkey" functions complicate matters by messing with the random number seed. More specifically, they keep resetting it back to a particular static value, which makes the odds of rednet collisions "near certain"!
Change these lines:
math.randomseed(math.random())
... so that the seed is a bit more unpredictable:
math.randomseed(os.clock())
math.random() isn't suitable as a seed in this instance because you've just set a seed of "keyhash" (which is the same every time - you read it from a file) and then rolled 32 values. The 33rd value, the one you use to set the new seed, is always going to be the same. The system clock is nearly certain to be different every time you check it, however.
The thing I'm scratching my head over is that if this is the problem - and I can't really see any other alternatives - it'd be the seed of the client system at fault, not the seed of the server. Hrm. Do systems share seeds? Might have to look into that one... Maybe you're simply running similar code on the client system...?
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











