rednet

The Rednet API allows systems to communicate between each other without using redstone. It serves as a wrapper for the modem API, offering ease of functionality (particularly in regards to repeating signals) with some expense of fine control.

In order to send and receive data, a modem (either wired, wireless, or ender) is required. The data reaches any possible destinations immediately after sending it, but is range limited.

Rednet also allows you to use a "protocol" - simple string names indicating what messages are 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 use certain protocols, hence making it easier to determine where given messages should be sent in the first place.

CHANNEL_BROADCAST = 65535The channel used by the Rednet API to broadcast messages.
CHANNEL_REPEAT = 65533The channel used by the Rednet API to repeat messages.
open(modem)Opens a modem with the given peripheral name, allowing it to send and receive messages over rednet.
close([modem])Close a modem with the given peripheral name, meaning it can no longer send and receive rednet messages.
isOpen([modem])Determine if rednet is currently open.
send(nRecipient, message[, sProtocol])Allows a computer or turtle with an attached modem to send a message intended for a system with a specific ID.
broadcast(message[, sProtocol])Broadcasts a string message over the predefined CHANNEL_BROADCAST channel.
receive([sProtocolFilter[, nTimeout]])Wait for a rednet message to be received, or until nTimeout seconds have elapsed.
host(sProtocol, sHostname)Register the system as "hosting" the desired protocol under the specified name.
unhost(sProtocol)Stop hosting a specific protocol, meaning it will no longer respond to rednet.lookup requests.
lookup(sProtocol[, sHostname])Search the local rednet network for systems hosting the desired protocol and returns any computer IDs that respond as "register...
run()Listen for modem messages and converts them into rednet messages, which may then be received.
CHANNEL_BROADCAST = 65535Source

The channel used by the Rednet API to broadcast messages.

CHANNEL_REPEAT = 65533Source

The channel used by the Rednet API to repeat messages.

open(modem)Source

Opens a modem with the given peripheral name, allowing it to send and receive messages over rednet.

This will open the modem on two channels: one which has the same ID as the computer, and another on the broadcast channel.

Parameters

  1. modem string The name of the modem to open.

Throws

  • If there is no such modem with the given name

close([modem])Source

Close a modem with the given peripheral name, meaning it can no longer send and receive rednet messages.

Parameters

  1. modem? string The side the modem exists on. If not given, all open modems will be closed.

Throws

  • If there is no such modem with the given name

isOpen([modem])Source

Determine if rednet is currently open.

Parameters

  1. modem? string Which modem to check. If not given, all connected modems will be checked.

Returns

  1. boolean If the given modem is open.
send(nRecipient, message[, sProtocol])Source

Allows a computer or turtle with an attached modem to send a message intended for a system with a specific ID. 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.

Parameters

  1. nRecipient number The ID of the receiving computer.
  2. message The message to send. This should not contain coroutines or functions, as they will be converted to nil.
  3. sProtocol? string The "protocol" to send this message under. When using rednet.receive one can filter to only receive messages sent under a particular protocol.

Returns

  1. boolean If this message was successfully sent (i.e. if rednet is currently open). Note, this does not guarantee the message was actually received.

See also

broadcast(message[, sProtocol])Source

Broadcasts a string message over the predefined CHANNEL_BROADCAST channel. The message will be received by every device listening to rednet.

Parameters

  1. message The message to send. This should not contain coroutines or functions, as they will be converted to nil.
  2. sProtocol? string The "protocol" to send this message under. When using rednet.receive one can filter to only receive messages sent under a particular protocol.

See also

receive([sProtocolFilter[, nTimeout]])Source

Wait for a rednet message to be received, or until nTimeout seconds have elapsed.

Parameters

  1. sProtocolFilter? string The protocol the received message must be sent with. If specified, any messages not sent under this protocol will be discarded.
  2. nTimeout? number The number of seconds to wait if no message is received.

Returns

  1. number The computer which sent this message
  2. The received message
  3. string | nil The protocol this message was sent under.

Or

  1. nil If the timeout elapsed and no message was received.

See also

host(sProtocol, sHostname)Source

Register the system as "hosting" the desired protocol under the specified name. If a rednet lookup is performed for that protocol (and maybe name) on the same network, the registered system will automatically respond via a background process, hence providing the system performing the lookup with its ID number.

Multiple computers may not register themselves on the same network as having the same names against the same protocols, and the title localhost is specifically reserved. They may, however, share names as long as their hosted protocols are different, or if they only join a given network after "registering" themselves before doing so (eg while offline or part of a different network).

Parameters

  1. sProtocol string The protocol this computer provides.
  2. sHostname string The name this protocol exposes for the given protocol.

Throws

  • If trying to register a hostname which is reserved, or currently in use.

See also

unhost(sProtocol)Source

Stop hosting a specific protocol, meaning it will no longer respond to rednet.lookup requests.

Parameters

  1. sProtocol string The protocol to unregister your self from.
lookup(sProtocol[, sHostname])Source

Search the local rednet network for systems hosting the desired protocol and returns any computer IDs that respond as "registered" against it.

If a hostname is specified, only one ID will be returned (assuming an exact match is found).

Parameters

  1. sProtocol string The protocol to search for.
  2. sHostname? string The hostname to search for.

Returns

  1. { number } | nil A list of computer IDs hosting the given protocol, or nil if none exist.

Or

  1. number | nil The computer ID with the provided hostname and protocol, or nil if none exists.
run()Source

Listen for modem messages and converts them into rednet messages, which may then be received.

This is automatically started in the background on computer startup, and should not be called manually.