Modem networking

Computers in ComputerCraft in general can network through various ways. In this section, we will only explore the modem networking, although you can also communicate through redstone or mods.

Todo

A honorable mention to OpenComputers’ modem API. OC actually seems to support direct addressing on a hardware level, where CC only supports broadcasting on channels; this would make the abstractions more complicated if I ever want to make a global abstraction for both one day…

Definitions

A modem is a device that allows a computer to send messages on a given port. Messages are broadcasted to other computers listening on the given port in certain conditions, such as range.

A port has a numerical identifier between 1 and 65535 included. There can be a hard limit to how many ports can be simultaneously opened, for example ComputerCraft modems only support 128 ports opened at once.

Messages can have varying types according to the modem type. Some examples are:

  • ComputerCraft modem messages can be a string, a number, or a table combining these types.

  • Skynet modem messages can be any message CBOR-encodable.

ComputerCraft modems

Modem types represented in ComputerCraft.

The three modem types in ComputerCraft, as represented in game. From left to right: wired modem, wireless modem, ender modem.

ComputerCraft adds three different kinds of modems:

  • wired modems, which allows a computer to be connected to another through wires.

  • wireless modems, which allows a computer to be connected to others without wires with a limited range depending on the weather; see Wireless range.

  • ender modems are similar to wireless modems (in fact, ComputerCraft recognizes them as “advanced” wireless modems), except that for a given channel, they can communicate with all wireless and ender modems in all dimensions, and listen to all communications from wireless and ender modems from all dimensions; see WirelessNetwork.tryTransmit (where interdimensional is set for packets sent by ender modems, and receiver.isInterdimensional is true if the receiver is an ender modem).

Note that what ComputerCraft wiki calls dimensions corresponds to what Mojang mappings calls worlds (hence the technical name net.minecraft.world.World).

All modems work the same: datagrams are sent on ports whose numbers vary between 0 and 65535 (see modem.open). Through such a modem, computers can send a message from any arbitrary port, and receive messages on up to 128 simultaneously opened ports at once.

Note

The opened port limit can be pushed further by using several modems on a computer; e.g. up to 256 ports can be opened when two wireless modems are connected.

Messages are Lua strings, numbers, or tables; metatables are not transmitted along the way, probably a byproduct of using the @LuaFunction decorator from Cobalt in ComputerCraft.

Any message on the given modems also send along the pipe the “reply channel”, which for Rednet-enabled devices corresponds to the source channel. Note that this can be set by the user program when sending a message and does not correspond to a MAC address or anything, therefore cannot be used as a reliable source port (see Rednet).

When receiving a message, in the produced modem_message event in CraftOS, wireless and ender modems within the same dimensions include the distance from the emitting device; this specificity is used on some protocols, such as the GPS one (see GPS protocol).

Note

Although modem as blocks use integer coordinates, even turtles when they move (positions update immediately to the new block position), some modems can have decimal positions, most importantly pocket computers, linked to the player’s coordinates.

Classic GPS hosts round the coordinates with a .01 precision.

Wireless range

The wireless range formula for basic wireless modems is the following:

\begin{cases}
        D_{max} = R_{low} + (y - 96) * ((R_{high} - R_{low}) / (Y_{max} - 1 - 96) \text{ if $y > 96$} \\
        D_{max} = R_{low} \text{ if $y <= 96$}
\end{cases}

Where the variables are the following:

  • y is the modem’s y coordinate.

  • Y_{max} is the maximum Y coordinate, equal to 256 in Minecraft 1.16.

  • R_{low} represents the range of wireless modems at “low altitude”, i.e. at y = 96 and below; it is configurable, but is of 64 in both clear weather and storm.

  • R_{high} represents the range of wireless modems at “high altitude”, i.e. at y = Y_{max}; it is configurable, but is of 384 in both clear weather and storm.

Note

In legacy ComputerCraft, the values were the following:

Weather

Range at low alt.

Range at high alt.

Clear

64

384

Storm

16

96

Wireless range evolution.

A vizualization of the range depending on the current y coordinate, with Y_{max} being defined to 256, its current value. The values taken for clear and stormy weathers are those of legacy ComputerCraft.

See WirelessModemPeripheral.getRange, Config.Config and ComputerCraft.modemRange for reference.

Skynet modems

Skynet is a virtual modem running on top of websockets.

Todo

Describe Skynet. Some elements I have understood for now:

  • Base URLs are wss://osmarks.tk/skynet2/connect/.

  • Can use numbers, strings, tables as channel names.

rednoot modems

Todo

See what I can find about rednoot, and if it’s even interesting.