Rednet API

 Note: This function call requires a Modem peripheral to be attached to the computer. See Networking for more information.

 Note: Rednet is not secure against interception or spoofing. See Network security#Rednet for more information.

Functionrednet.broadcast
Broadcasts a string message over the predefined rednet.CHANNEL_BROADCAST channel (default 65535), assuming rednet has been opened. The message will be received by every device listening to rednet.

 Note: This function call requires a Modem peripheral to be attached to the computer. See Networking for more information.

 Note: Rednet is not secure against interception or spoofing. See Network security#Rednet for more information.
Syntax rednet.broadcast(
  • message : any
  • protocol? : string
)
Returns nil
Part of CC:Tweaked (source)
API rednet
ExampleBroadcast a 'Ping' message over rednet.
Broadcasts 'Ping' over the defined rednet.CHANNEL_BROADCAST channel.
Code
<nowiki>
rednet.broadcast('Ping')
    </nowiki>
Output Users running rednet.receive will now have received 'Ping' in their programs.
Functionrednet.close
Closes rednet on the modem attached to side.

 Note: This function call requires a Modem peripheral to be attached to the computer. See Networking for more information.

 Note: Rednet is not secure against interception or spoofing. See Network security#Rednet for more information.
Syntax rednet.close(
  • side : string
)
Returns nil
Part of CC:Tweaked (source)
API rednet
See also rednet.open
ExampleClose the top modem.
If rednet is open on the top modem on the computer, this will close it.
Code
<nowiki>
rednet.close("top")
    </nowiki>
Output Rednet events will no longer trigger on the top modem.

Rednet.host

Functionrednet.isOpen
Checks if a modem is open on Rednet. channel must be a Modem or side, like “modem_1234” or “top”
Syntax rednet.isOpen(
  • Modem : string
)
Returns boolean open
Part of CC:Tweaked (source)
API rednet
ExampleCheck if modem_1234 is open
Check if modem_1234 is open.
Code
<nowiki>
local modem = peripheral.wrap("modem_1234")
print(rednet.isOpen(modem))
    </nowiki>
Output
true

Rednet.lookup

Functionrednet.open
Opens rednet on the modem attached to side.

 Note: This function call requires a Modem peripheral to be attached to the computer. See Networking for more information.

 Note: Rednet is not secure against interception or spoofing. See Network security#Rednet for more information.
Syntax rednet.open(
  • side : string
)
Returns nil
Part of CC:Tweaked (source)
API rednet
See also rednet.close
ExampleOpen the top modem.
Opens rednet on the top modem of the computer.
Code
<nowiki>
rednet.open("top")
    </nowiki>
Output Rednet events will now trigger on the top modem.
ExampleOpen all connected modems
This is a little trick using peripheral.find. It accepts a function as the second argument, which is called for each matching peripheral. By using rednet.open here, every connected modem is opened.
Code
<nowiki>
peripheral.find("modem", rednet.open)
    </nowiki>
Functionrednet.receive
Waits for a Rednet message to be received by an opened modem, or until timeout seconds elapse. Takes another optional parameter, which limits messages able to be received to those broadcasted or sent with a matching protocol.

 Note: This function call requires a Modem peripheral to be attached to the computer. See Networking for more information.

 Note: Rednet is not secure against interception or spoofing. See Network security#Rednet for more information.
Syntax rednet.receive(
  • protocol? : string
  • timeout? : number
)
Returns number senderID, any message, string protocol
Part of Rednet API (source)
API rednet
ExampleReceive any message with no timeout
Since we have no arguments, rednet.receive will wait for the next message from any protocol. If a rednet message was received with the text "Hello world!", the the output would be as follows:
Code
<nowiki>
local id, message, protocol = rednet.receive()
print(message)
    </nowiki>
Output
"Hello world!"
ExampleReceive any message with a timeout
Since we have our timeout specified, rednet.receive will wait for the next message from any protocol, or until the timeout is up. If a rednet message was received with the text "Now there's a timeout!" before the timeout is up, the the output would be as follows:
Code
<nowiki>
local id, message, protocol = rednet.receive(30)
print(message)
    </nowiki>
Output
"Now there's a timeout!"
ExampleReceive messages of a certain protocol with a timeout
Since we have our timeout and protocol specified, rednet.receive will wait for the next message from a specific protocol, or until the timeout is up. If a rednet message was received with the text "Now there's a protocol!" and protocol "ComputerCraft" before the timeout is up, the the output would be as follows:
Code
<nowiki>
local id, message, protocol = rednet.receive("ComputerCraft", 30)
print(message)
    </nowiki>
Output
"Now there's a protocol!"

Rednet.run

Functionrednet.send
Sends a Rednet message to be received by a specific computer (whose id is id.) Takes another optional parameter, protocol, which specifies what the message is for. It returns false if the message was unable to be sent, but true if it was sent.

Make sure your modem is opened with rednet.open!

 Note: This function call requires a Modem peripheral to be attached to the computer. See Networking for more information.

 Note: Rednet is not secure against interception or spoofing. See Network security#Rednet for more information.
Syntax rednet.send(
  • id : number
  • message : any
  • protocol? : string
)
Returns bool success
Part of Rednet API (source)
API rednet
ExampleSend a message to a computer
We send a message to the computer whose id is 567. If the message could be sent, we should see an output of true:
Code
<nowiki>
print(rednet.send(567, "Hello world!"))
    </nowiki>
Output
true
ExampleSend a message to a computer with a protocol
We now send a message to the computer whose id is 890, with a protocol of "ComputerCraft". If it was sent, we will see a true output:
Code
<nowiki>
print(rednet.send(890, "Hello world!", "ComputerCraft"))
    </nowiki>
Output
true

Rednet.unhost

This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.