Network: Difference between revisions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
The NetworkUD component allows sending network packets to other [[Computer|Computers]], connected via [[Network Cable|Network Cables]], [[Network Router|Network Routers]] and [[Wan Router|Wan Routers]]. Upon sending a packet, the shortest path is calculated (only utilizing WAN routers if absolutely necessary), and after some time (which depends on the distance) the packet is emitted on the destination computer in the form of a <code>networkPacket</code> machine event, as described in [[Computer#Machine events]]. | The NetworkUD component allows sending network packets to other [[Computer|Computers]], connected via [[Network Cable|Network Cables]], [[Network Router|Network Routers]] and [[Wan Router|Wan Routers]]. Upon sending a packet, the shortest path is calculated (only utilizing WAN routers if absolutely necessary), and after some time (which depends on the distance) the packet is emitted on the destination computer in the form of a <code>networkPacket</code> machine event, as described in [[Computer#Machine events]]. | ||
A packet will only be received on the destination computer if the destination's port is open. | A packet will only be received on the destination computer if the destination's port is open. The source computer does not require any ports to be open for transmitting to work. | ||
{| class="wikitable" | {| class="wikitable" | ||
Revision as of 10:12, 18 August 2026
The NetworkUD component allows sending network packets to other Computers, connected via Network Cables, Network Routers and Wan Routers. Upon sending a packet, the shortest path is calculated (only utilizing WAN routers if absolutely necessary), and after some time (which depends on the distance) the packet is emitted on the destination computer in the form of a networkPacket machine event, as described in Computer#Machine events.
A packet will only be received on the destination computer if the destination's port is open. The source computer does not require any ports to be open for transmitting to work.
| Name | Type | Read/Write | Description |
|---|---|---|---|
maxPacketSize |
integer |
READ | The maximum amount of characters in a network message. Set in the server's config. |
| Name | Returns | Description |
|---|---|---|
:send(address:string, port:int, message:string)
|
void
|
Sends a message to the target computer. |
:openPort(port:int)
|
boolean
|
Opens the given local port. Returns true if the port was not open previously.
|
:closePort(port:int)
|
boolean
|
Closes the given local port. Returns true if the port was open previously.
|
| :closeAllPorts() | int | Closes all local ports. Returns the number of ports that were open. |
:isPortOpen(port:int)
|
boolean
|
Returns whether the given port is currently open. |
Notes
Network packets take a while to arrive at their destination. The duration is computed by the sum of distances between network routers along the path, with a large added penalty if the transmission has to go through a pair of WAN routers, and an even bigger penalty if it needs to travel across dimensions. By default packets travel 1000 blocks per second, though this can be changed in the config file.