rednet.send

From ComputerCraft Wiki
Jump to: navigation, search


Grid Redstone.png  Function rednet.send
Allows a computer / turtle with an attached modem to send a message intended for a system with a specific ID (compare rednet.broadcast(), which aims to target everything in range). At least one such modem must first be "opened" before sending is possible. Assuming the target was in range and also had a correctly opened modem, it may then use rednet.receive() to collect the message.

Messages are transmitted on a channel number equal to the target system's ID, with a suggested "reply" channel equal to the sending system's ID. Be aware that if other users are in range of your wireless network, or cabled into your wired network, knowing / guessing your target ID number will allow them to manually open that channel on their own systems in order to receive your messages. As of ComputerCraft 1.6, all rednet messages are additionally sent on channel 65533 (allowing the repeat script to easily detect them).

ComputerCraft 1.6 also introduces "protocol" - simple string names indicating what the message is about. Receiving systems may filter messages according to their protocols, thereby automatically ignoring incoming messages which don't specify an identical string. It's also possible to lookup which systems in the area are interested in certain protocols, hence making it easier to determine where given messages should be sent in the first place.

Messages are typically strings, however later versions of ComputerCraft (which?) may alternatively send tables instead. Those users still on older versions may find textutils.serialize() useful when wanting to transmit tables.
Syntax rednet.send(number receiverID, string message, [string protocol])
Returns boolean success code. True if a message has been sent (note - "sent", as opposed to "received" or even "was receivable"), false if not.
Part of ComputerCraft
API rednet

Examples

Grid paper.png  Example
Sends a message to the system with the ID of 22 (assuming a modem is attached and open).
Code
rednet.send(22,"ComputerCraft")



Grid paper.png  Example
Sends a message to the system with the ID of 22, specifying a protocol of "TestMessages".
Code
rednet.send(22,"ComputerCraft","TestMessages")


Grid disk.png Rednet API Functions
rednet.open - rednet.close - rednet.send - rednet.broadcast - rednet.receive - rednet.isOpen - rednet.host - rednet.unhost - rednet.lookup
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox