Description
This component is provided by network cards.
Component name: modem.
This component is provided by network cards.
Component name: modem.
isWireless(): boolean Returns whether this modem is capable of sending wireless messages.
maxPacketSize(): number Returns the maximum packet size for sending messages via network cards. Defaults to 8192. You can change this in the OpenComputers configuration file.isOpen(port: number): boolean Returns whether the specified “port” is currently being listened on. Messages only trigger signals when they arrive on a port that is open.
open(port: number): boolean Opens the specified port number for listening. Returns true if the port was opened, false if it was already open. Note: maximum port is 65535
close([port: number]): boolean Closes the specified port (default: all ports). Returns true if ports were closed.
send(address: string, port: number[, ...]): boolean Sends a network message to the specified address. Returns true if the message was sent. This does not mean the message was received, only that it was sent. No port-sniffing for you.broadcast(port: number, ...): boolean Sends a broadcast message. This message is delivered to all reachable network cards. Returns true if the message was sent. Note that broadcast messages are not delivered to the modem that sent the message.
All additional arguments are passed along as data. See send.
getStrength(): number The current signal strength to apply when sending messages. Wireless network cards only.
setStrength(value: number): number Sets the signal strength. If this is set to a value larger than zero, sending a message will also generate a wireless message. The higher the signal strength the more energy is required to send messages, though. Wireless network cards only.
getWakeMessage():string Gets the current wake-up message. When the network card detects the wake message (a string in the first argument of a network packet), on any port and the machine is off, the machine is started. Works for robots, cases, servers, drones, and tablets. Linked Cards provide this same functionality.
setWakeMessage(message: string, [fuzzy: boolean]):string Sets the wake-up message to the specified string. The message matching can be fuzzy (default is false). A fuzzy match ignores additional trailing arguments in the network packet.
modem_message(receiverAddress: string, senderAddress: string, port: number, distance: number, ...)
This signal is queued by network cards (including wireless ones) when they receive a message on an open port.
receiverAddress is the address of the network card that received the message.
senderAddress is the address from where the message was sent.
port is the port on which the message was received.
distance is the distance only set when receiving wireless network messages.
All further parameters are user defined and correspond to what the sender specified in modem.send() or modem.broadcast() as the message's payload.
-- https://ocdoc.cil.li/component:modem
local component = require("component")
local event = require("event")
local m = component.modem -- get primary modem component
m.open(123)
print(m.isOpen(123)) -- true
-- Send some message.
m.broadcast(123, "this is a test")
-- Wait for a message from another network card.
local _, _, from, port, _, message = event.pull("modem_message")
print("Got a message from " .. from .. " on port " .. port .. ": " .. tostring(message))