modem

The modem peripheral allows you to send messages between computers.

open(channel)Open a channel on a modem.
isOpen(channel)Check if a channel is open.
close(channel)Close an open channel, meaning it will no longer receive messages.
closeAll()Close all open channels.
transmit(channel, replyChannel, payload)Sends a modem message on a certain channel.
isWireless()Determine if this is a wired or wireless modem.
getNamesRemote()List all remote peripherals on the wired network.
isPresentRemote(name)Determine if a peripheral is available on this wired network.
getTypeRemote(name)Get the type of a peripheral is available on this wired network.
getMethodsRemote(name)Get all available methods for the remote peripheral with the given name.
callRemote(remoteName, method, ...)Call a method on a peripheral on this wired network.
getNameLocal()Returns the network name of the current computer, if the modem is on.
open(channel)Source

Open a channel on a modem. A channel must be open in order to receive messages. Modems can have up to 128 channels open at one time.

Parameters

  1. channel number The channel to open. This must be a number between 0 and 65535.

Throws

  • If the channel is out of range.

  • If there are too many open channels.

isOpen(channel)Source

Check if a channel is open.

Parameters

  1. channel number The channel to check.

Returns

  1. boolean Whether the channel is open.

Throws

  • If the channel is out of range.

close(channel)Source

Close an open channel, meaning it will no longer receive messages.

Parameters

  1. channel number The channel to close.

Throws

  • If the channel is out of range.

closeAll()Source

Close all open channels.

transmit(channel, replyChannel, payload)Source

Sends a modem message on a certain channel. Modems listening on the channel will queue a modem_message event on adjacent computers.

Note: The channel does not need be open to send a message.

Parameters

  1. channel number The channel to send messages on.
  2. replyChannel number The channel that responses to this message should be sent on.
  3. payload any The object to send. This can be a string, number, or table.

Throws

  • If the channel is out of range.

isWireless()Source

Determine if this is a wired or wireless modem.

Some methods (namely those dealing with wired networks and remote peripherals) are only available on wired modems.

Returns

  1. boolean true if this is a wireless modem.
getNamesRemote()Source

List all remote peripherals on the wired network.

If this computer is attached to the network, it will not be included in this list.

Important: This function only appears on wired modems. Check @{isWireless} returns false before calling it.

Returns

  1. { string... } Remote peripheral names on the network.
isPresentRemote(name)Source

Determine if a peripheral is available on this wired network.

Important: This function only appears on wired modems. Check @{isWireless} returns false before calling it.

Parameters

  1. name string The peripheral's name.

Returns

  1. boolean boolean If a peripheral is present with the given name.

See also

getTypeRemote(name)Source

Get the type of a peripheral is available on this wired network.

Important: This function only appears on wired modems. Check @{isWireless} returns false before calling it.

Parameters

  1. name string The peripheral's name.

Returns

  1. string | nil The peripheral's type, or nil if it is not present.

See also

getMethodsRemote(name)Source

Get all available methods for the remote peripheral with the given name.

Important: This function only appears on wired modems. Check @{isWireless} returns false before calling it.

Parameters

  1. name string The peripheral's name.

Returns

  1. { string... } | nil A list of methods provided by this peripheral, or nil if it is not present.

See also

callRemote(remoteName, method, ...)Source

Call a method on a peripheral on this wired network.

Important: This function only appears on wired modems. Check @{isWireless} returns false before calling it.

Parameters

  1. remoteName string The name of the peripheral to invoke the method on.
  2. method string The name of the method
  3. ... Additional arguments to pass to the method

Returns

  1. string The return values of the peripheral method.

See also

getNameLocal()Source

Returns the network name of the current computer, if the modem is on. This may be used by other computers on the network to wrap this computer as a peripheral.

Important: This function only appears on wired modems. Check @{isWireless} returns false before calling it.

Returns

  1. string | nil The current computer's name on the wired network.