50 posts
Location
South Africa
Posted 30 November 2013 - 08:53 AM
So I'm planning to use Rednet to wirelessly transfer messages from computer to computer. I was going through the wiki and came across two methods which I'm unsure about.
The first method was the Rednet API method : rednet.broadcast()
The second method was the Modem API method : modem.transmit()
I just wanted to make sure, but is the Modem API modem.transmit() restricted to networks that use the networking cable as backbone? Or can this API be used through the Wireless modems without the need of any networking cables?
758 posts
Location
Budapest, Hungary
Posted 30 November 2013 - 09:18 AM
The
modem API doesn't acutally exist. You get that API (not really an API, just a table with a bunch of functions) when you wrap up a modem with
peripheral.wrap(<modem_side>). The rednet API something that makes controlling modems easier by providing another bunch of functions (namely .broadcast, .send, .receive). In order to be able to control modems (and send messages either wirelessly or through networking cables), you have to tell the rednet API which modem to use (so
rednet.open(<modem_side>)). In case that did not make sense:
rednet.open("top") -- suppose we have a modem on the top of the computer
rednet.send(3, "handshake") -- send something to computer #3 (although every computer with a modem will get that message, the ones working with rednet only won't notice)
rednet.broadcast("watch out!") -- every computer will get that message, even the ones working with rednet only
local sender, message = rednet.receive(3) -- will return after 3 seconds if no message arrives
print(message or "Timed out")
local sender, message = rednet.receive() -- no timeout provided, won't return until a message arrives
print("Computer #" .. tostring(sender) .. " is complaining again")
Point is, you'll only need
rednet.open,
rednet.send and
rednet.receive (and
rednet.close, occasionally).
Edited on 30 November 2013 - 08:18 AM
7083 posts
Location
Tasmania (AU)
Posted 30 November 2013 - 03:55 PM
The rednet API is also "a table with a bunch of functions". As are the rest of them.
The modem API can be used to do anything the rednet API can, and more (with the exception of the time-out thing, which you can handle yourself with a simple timer event). In fact, most everything the rednet API does is performed by calling the modem API for you - the one can be used to pick up transmissions from the other, and vice versa.
The rednet version is maybe a little "simpler" for the beginner, but by using it you forgo the "fine control" you'd otherwise get by using the modem API directly. Frankly I feel the rednet version is redundant and has an unfortunate side effect of misleading newbies as to how ComputerCraft networking really works.
8543 posts
Posted 30 November 2013 - 04:32 PM
I disagree. The rednet API is a useful abstraction that serves a specific use. When one wants computer-to-computer communications based on the computer ID, the rednet API provides a useful way of abstracting out the modem calls. It simplifies programs that don't need to multicast (which most don't) and don't desire to use custom frequencies to attempt to obscure their communications. Many applications don't require all of the features of the direct use of the modem transmission calls and benefit from the simpler, cleaner rednet API calls. The other advantage of rednet calls is that they provide a convenient overriding point for networking APIs that add packet forwarding capabilities. LyqydNet will encapsulate and forward packets sent with rednet.send calls that are trying to reach a host that is beyond immediate rednet range, but leave alone packets to those hosts that are within range. This enables "free" extensions of the capability of programs that are written to use rednet API calls.
7083 posts
Location
Tasmania (AU)
Posted 30 November 2013 - 05:21 PM
The "useful abstraction" argument could be made for adding many similar such APIs to ComputerCraft - of course, were one to suggest they be added, they'd all rejected as that's one of the sorts of things referred to on the "do not ask for this" list. That is to say, anyone could potentially write their own wrapper if they merely wanted "abstraction" or "cleaner calls".
Don't get me wrong, I don't think it should be removed - I recognise full well that it's too entrenched to even consider. I've just come to take a disliking to the confusion it can cause, so at some point you'll probably see me attempting a re-write of its wiki documentation. (Should I ever get the time. I've been plotting that for months.)
8543 posts
Posted 30 November 2013 - 05:30 PM
We weren't discussing adding other APIs to ComputerCraft, only whether or not the rednet API was redundant and of limited utility.
Updated documentation is never a bad thing, as long as it isn't written from the perspective of, "here's why this API is redundant and should never be used".
7083 posts
Location
Tasmania (AU)
Posted 30 November 2013 - 06:46 PM
Don't worry, you rest assured that's not what I've got in mind. ;)/>