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

Is delivery of rednet messages guaranteed?

Started by lincore, 25 March 2014 - 08:53 AM
lincore #1
Posted 25 March 2014 - 09:53 AM
Hello guys.

Given that sender and receiver are both located in loaded chunks and communication does work under normal circumstances (in wireless range, no race conditions or other bugs etc.), is it possible that messages that were send get "lost" under certain conditions? I do not mean stuff like "sure the server could be hit by a jet turbine during the process", but more probable causes like high server load etc. Also, are messages always delivered in order? Any other caveats I might have missed?

I'm currently writing a small library to abstract the whole rednet communication process into a few neat classes and I am wondering whether it's necessary to acknowledge every received message, do length comparisons, make sure they were delivered in order etc. I can't simulate the extraordinary circumstances that I worry most about, so I hope you guys can help me out.
oeed #2
Posted 25 March 2014 - 10:00 AM
Well, one of the big things that could cause issues is if you have fairly time consuming actions (such as complex drawing, or even sleep [although that would be silly to do so]) then there's a chance it'd get missed.

Although, now I think about it, events are queued. So unless you're not in range or the channels not open or something along those lines then, yes, messages should always get there. I could be incorrect though.
theoriginalbit #3
Posted 25 March 2014 - 10:04 AM
well Rednet is already a library to abstract communication. Communication now is done through the api on modems directly.

however assuming that the two computers are within range of each other, yes a message will always be received. the common problem however is people using functions such as sleep, read, the turtle api, and several other functions which yield. when these functions yield quite often they're waiting for a specific event, or a set of specific events. this means that any other event that happens in the mean time gets lost. however the only way for your library to be effective will be via use of the parallel api (coroutines) meaning that you'll not have to worry about this specific problem as each coroutine is notified about events, so long as you don't use sleep or anything else that yields (other than os.pullEvent/os.pullEventRaw/coroutine.yield) you'll never miss a modem_message event.

the one thing I do suggest to you, you're making a library to deal with communications so definitely use the Modems directly; don't use the Rednet API. if you want to know exactly how the Rednet API works — and how interaction with modems work — take a look at the Rednet APIs source with edit rom/apis/rednet.
Bomb Bloke #4
Posted 25 March 2014 - 10:28 AM
In my experience, the messages are sometimes missed, even if there's no good reason for it to happen - a system can be sitting there waiting for a message to come in, and it just… doesn't get it. This might happen once or twice per day, assuming continuous messages at least every couple of minutes over that period. Because of this I make use of time-outs and resends in my code.

Heck, once I had a turtle miss the event that told it a turtle.forward() had finished up. Little sucker was in the middle of a trivial "for" loop and just stopped dead in its tracks until I climbed up and forcibly rebooted it.