Difference between revisions of "Rednet (API)"

From ComputerCraft Wiki
Jump to: navigation, search
m (Events fix.)
(Updated to API overview v2)
Line 1: Line 1:
The rednet API allows computers to communicate between themselves without using redstone wires. In order to send and receive data, a [[modem]] is required. The data is received immediately after sending it, but only by computers within a certain range. That range depends on the altitude of the sending computer increasing with higher altitudes to a max of 384.
+
The Rednet API allows computers to communicate between themselves without using redstone wires. In order to send and receive data, a [[modem]] is required. The data is received immediately after sending it, but only by computers within a certain range. That range depends on the altitude of the sending computer increasing with higher altitudes to a max of 384.
  
==History==
+
<table style="width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;">
Before the creation of the in-game wireless networking API, the term "Rednet" referred to a system created by one of the ComputerCraft users based on bundled cables from a popular Minecraft mod - RedPower. It also allowed communication between computers, but the data was transferred slowly - every bit was converted to redstone signal, that lasted about 0,1 seconds. On the release of ComputerCraft 1.3, the system became useless, as the wireless networking was officially implemented to the mod.
+
<tr><td colspan="2" style="font-weight: bold; font-size: large; padding-bottom: .3em; border-bottom: solid #C9C9C9 1px; background: #D3FFC2; line-height:28px;">
 +
[[File:Grid_disk.png|24px]]&nbsp;&nbsp;
 +
Rednet (API)
 +
</td></tr>
  
==Methods==
+
<tr><td style="width: 350px; background: #E0E0E0; padding: .4em; font-weight:bold;">Method Name</td><td style="background: #E0E0E0; padding: .4em; font-weight:bold;">Description</td></tr>
{| border="1" cellpadding="5" cellspacing="0"
+
 
!style="background:#EEE" width="200px"|Method name
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[rednet.open]](side)</td>
!style="background:#EEE" width="*"|Description
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Tells the computer that the side can be used for networking.</td></tr>
!style="background:#EEE" width="80px"|Return type
+
 
|-
+
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[rednet.close]](side)</td>
|[[rednet.open]](side)
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Tells the computer that the side can no longer be used for networking.</td></tr>
|Tells the computer that the side can be used for networking.
+
 
|nil
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[rednet.announce]]()</td>
|-
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Broadcasts an empty rednet message.</td></tr>
|[[rednet.close]](side)
+
 
|Tells the computer that the side can no longer be used for networking.
+
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[rednet.send]](receiverID, message)</td>
|nil
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Sends a message to the computer using the opened sides. The receiver ID is the ID (number, not string) of the computer you're sending the message to. ID as nil will do the same as a broadcast.</td></tr>
|-
+
 
|[[rednet.announce]]()
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[rednet.broadcast]](message)</td>
|Broadcasts an empty rednet message.
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Sends the message to ALL connected and open computers.</td></tr>
|success
+
 
|-
+
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[rednet.receive]](timeout)</td>
|[[rednet.send]](receiverID, message)
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Waits until it received a rednet message or <var>timeout</var> has passed. Leave args empty to wait for a message forever.</td></tr>
|Sends a message to the computer using the opened sides. The receiver ID is the ID (number, not string) of the computer you're sending the message to. ID as nil will do the same as a broadcast.
+
 
|success
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">rednet.isOpen(side)</td>
|-
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns true if the wireless modem is open or nil if not. Returns 1 always.</td></tr>
|[[rednet.broadcast]](message)
+
</table>
|Sends the message to ALL connected and open computers.
+
|success
+
|-
+
|[[rednet.receive]](timeout)
+
|Waits until it received a rednet message or <var>timeout</var> has passed. Leave args empty to wait for a message forever.
+
|senderId, message, distance
+
|-
+
|rednet.isOpen(side)
+
|Returns true if the wireless modem is open or nil if not. Returns 1 always.
+
|Boolean, integer
+
|}
+
  
 
==Events==
 
==Events==
Line 48: Line 40:
 
|Fired when a rednet message is received (can be used as alternative for rednet.receive())
 
|Fired when a rednet message is received (can be used as alternative for rednet.receive())
 
|senderId, message, distance
 
|senderId, message, distance
 +
|}
 +
 +
==History==
 +
Before the creation of the in-game wireless networking API, the term "Rednet" referred to a system created by one of the ComputerCraft users based on bundled cables from a popular Minecraft mod - RedPower. It also allowed communication between computers, but the data was transferred slowly - every bit was converted to redstone signal, that lasted about 0,1 seconds. On the release of ComputerCraft 1.3, the system became useless, as the wireless networking was officially implemented to the mod.
 +
 
[[Category:APIs]]
 
[[Category:APIs]]

Revision as of 22:26, 30 November 2012

The Rednet API allows computers to communicate between themselves without using redstone wires. In order to send and receive data, a modem is required. The data is received immediately after sending it, but only by computers within a certain range. That range depends on the altitude of the sending computer increasing with higher altitudes to a max of 384.

Grid disk.png   Rednet (API)

Method NameDescription
rednet.open(side) Tells the computer that the side can be used for networking.
rednet.close(side) Tells the computer that the side can no longer be used for networking.
rednet.announce() Broadcasts an empty rednet message.
rednet.send(receiverID, message) Sends a message to the computer using the opened sides. The receiver ID is the ID (number, not string) of the computer you're sending the message to. ID as nil will do the same as a broadcast.
rednet.broadcast(message) Sends the message to ALL connected and open computers.
rednet.receive(timeout) Waits until it received a rednet message or timeout has passed. Leave args empty to wait for a message forever.
rednet.isOpen(side) Returns true if the wireless modem is open or nil if not. Returns 1 always.

Events

Event name Description Parameters
rednet_message Fired when a rednet message is received (can be used as alternative for rednet.receive()) senderId, message, distance

History

Before the creation of the in-game wireless networking API, the term "Rednet" referred to a system created by one of the ComputerCraft users based on bundled cables from a popular Minecraft mod - RedPower. It also allowed communication between computers, but the data was transferred slowly - every bit was converted to redstone signal, that lasted about 0,1 seconds. On the release of ComputerCraft 1.3, the system became useless, as the wireless networking was officially implemented to the mod.