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

How Do You Use Rednet?

Started by DarkNinja2462, 12 February 2012 - 03:04 PM
DarkNinja2462 #1
Posted 12 February 2012 - 04:04 PM
Ok so I TOTALLY DONT GET REDNET!
Can someone make a tutorial?
I wanted to make a Client/Server network with a bunch of routing computers. a.k.a. the internet.
How does it send messages?
Bundled Cable or Red Alloy Wire/RedStone????
Espen #2
Posted 12 February 2012 - 04:37 PM
The problem is that you can't have multiple computers 'talk' at the same time, or else the messages become garbled.
You can only have one computer at a time send a message over the rednet.

If that's still ok with you, then here a small tutorial:
  1. Connect at least two computers together via bundled cable.
  2. To send/receive anything on a computer, you have to open a side for communication first. So type rednet.open( side ) on both first, where 'side' is the side on each computer, where the bundled cable is connected to.
  3. On the receiving computer, execute (either via Lua interactive interpreter, or via a program) rednet.receive( timeout ), where 'timeout' is the number of seconds the computer will wait for a message to arrive.
  4. On the sending computer, execute rednet.send( id, message ), where id is the 'id' of the receiver and 'message' is the message you want to send. If the message was sent successfully, rednet.send will return 'true'.

You can also send a broadcast, which will send the message to every computer who listens:
rednet.broadcast( message )

There's also an announce feature, which is basically a broadcast with an empty-string message:
rednet.announce()
equivalent to
rednet.broadcast( "" )

To receive messages you are not limited to rednet.receive( timeout ).
Alternatively you can listen to the "rednet_message" event, e.g.:

rednet.open( "back" )

while true do
  event, id, message = os.pullEvent()

  if event == "rednet_message" then
	print( "Message from ID#"..id..":" )
	print( message )
  end
end
rednet.receive, as well as the "rednet_message" event will both return the ID of the sender as well as his message.

Edit: Forgot the rednet.open( "back ") in the code block.
Edited on 12 February 2012 - 03:40 PM
DarkNinja2462 #3
Posted 04 March 2012 - 06:40 PM
If you use rednet.recieve how do you get the computer id and message??
Advert #4
Posted 04 March 2012 - 06:43 PM
If you use rednet.recieve how do you get the computer id and message??


It's nearly the same as os.pullEvent():


local id, message = rednet.receive()
Dlcruz129 #5
Posted 30 September 2012 - 12:17 AM
The problem is that you can't have multiple computers 'talk' at the same time, or else the messages become garbled.

Well what are the chances that 2 people will send a message at the exact same moment?
Zoinky #6
Posted 30 September 2012 - 12:25 AM
The problem is that you can't have multiple computers 'talk' at the same time, or else the messages become garbled.
Wouldn't they need to send it within 5 milliseconds of the first message? Not sure. :S

EDIT: Woops. Fixed a typo. :)/>/>
Lyqyd #7
Posted 30 September 2012 - 01:05 AM
Please don't bring back topics this old. This information is outdated as of several versions ago. Rednet through the wireless modems does not suffer from collision issues.
Zoinky #8
Posted 30 September 2012 - 04:06 AM
Please don't bring back topics this old. This information is outdated as of several versions ago. Rednet through the wireless modems does not suffer from collision issues.
Sorry. Forgot to check the dates :S
PonyKuu #9
Posted 30 September 2012 - 07:29 AM
So, there is really no collisions? Also, are messages transfer instantly, or transfer time is dependent on their size?
Lyqyd #10
Posted 30 September 2012 - 07:39 AM
So, there is really no collisions? Also, are messages transfer instantly, or transfer time is dependent on their size?

Wireless rednet is instant, no collisions. Wired rednet (via bundled cable, which is still an option) is dependent on the size of the message, and collisions are possible if more than one computer attempts to transmit simultaneously, I believe.
PonyKuu #11
Posted 30 September 2012 - 09:10 PM
OK, thank you for the explanation :)/>/>'