Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
component:modem [2014/07/10 09:04]
vexatos
component:modem [2023/04/09 02:54] (current)
bioscreeper Added "Also, calls to set the strength that exceed the installed modem's maximum strength will simply set the modem's strength to it's maximum." to modem.setStrength() documenation
Line 1: Line 1:
 Component: Modem Component: Modem
 ================ ================
-This component is provided by [[item:​network_card|network cards]]. Wireless network cards behave much like normal network cards, but additionally send the message as a wireless "​packet"​ when a strength is set.+This component is provided by [[item:​network_card|network cards]]. Wireless network cards behave much like normal network cards, but additionally send the message as a wireless "​packet"​ when a strength is set. The modem'​s address must be used for networking. It can be found through component.modem.address.
  
 Component name: `modem`.  ​ Component name: `modem`.  ​
Line 8: Line 8:
 - `isWireless():​ boolean`  ​ - `isWireless():​ boolean`  ​
   Returns whether this modem is capable of sending wireless messages.   Returns whether this modem is capable of sending wireless messages.
-- `maxPacketSize():​ number` +- `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.+  Returns the maximum packet size for sending messages via network cards. Defaults to 8192. You can change this in the OpenComputers configuration file.   
 +  Every value in a message adds two bytes of overhead. (Even if there'​s only one value.) ​  
 +  Numbers add another 8 bytes, true/​false/​nil another 4 bytes, and strings exactly as many bytes as the string contains---though empty strings still count as one byte.   
 +  Examples: ​  
 +  * `"​foo"​` is a 5-byte packet; two bytes of overhead and a three byte string. 
 +  * `"​currentStatus",​300` is a 25-byte packet; four bytes overhead, a 13-byte string, and 8 bytes for a number. 
 - `isOpen(port:​ number): boolean`  ​ - `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.   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`  ​ - `open(port: number): boolean`  ​
-  Opens the specified port number for listening. Returns `true` if the port was opened, `false` if it was already open.+  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`  ​ - `close([port:​ number]): boolean`  ​
   Closes the specified port (default: all ports). Returns true if ports were closed.   Closes the specified port (default: all ports). Returns true if ports were closed.
 - `send(address:​ string, port: number[, ...]): boolean`  ​ - `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.  ​   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.  ​
-  Any additional arguments are passed along as data. These arguments must be basic types: nil, boolean, number and string values are supported, tables and functions are not. See [[the text API|API/Text]] for serialization of tables.+  Any additional arguments are passed along as data. These arguments must be basic types: nil, boolean, number and string values are supported, tables and functions are not. See [[api:​serialization|the serialization ​API]] for serialization of tables.   
 +  The number of additional arguments is limited. The default limit is 8. It can be changed in the OpenComputers configuration file, but this is //not// recommended;​ higher limits can allow relatively weak computers to break relatively strong ones with no defense possible, while lower limits will prevent some protocols from working.
 - `broadcast(port:​ number, ...): boolean`  ​ - `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.  ​   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`.   All additional arguments are passed along as data. See `send`.
 - `getStrength():​ number`  ​ - `getStrength():​ number`  ​
-  The current signal strength to apply when sending messages. ​ +  The current signal strength to apply when sending messages.
   //Wireless network cards only.//   //Wireless network cards only.//
 - `setStrength(value:​ number): number`  ​ - `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. ​ +  Sets the signal strength. If this is set to a value larger than zero, sending a message will also generate a wireless message. ​Also, calls to set the strength that exceed the installed modem'​s maximum strength will simply set the modem'​s strength to it's maximum.  ​The higher the signal strength the more energy is required to send messages, though.
   //Wireless network cards only.//   //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. [[component:​tunnel|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.
  
  
Line 47: Line 58:
 print(m.isOpen(123)) -- true print(m.isOpen(123)) -- true
 -- Send some message. -- Send some message.
-m.broadcast(321, "this is a test")+m.broadcast(123, "this is a test")
 -- Wait for a message from another network card. -- Wait for a message from another network card.
 local _, _, from, port, _, message = event.pull("​modem_message"​) local _, _, from, port, _, message = event.pull("​modem_message"​)