NetSystem¶
Extends EngineObject.
The game's network: connections to other programs over UDP, with encryption, in order and reliably or not as each message asks (GameNetworkingSockets, Valve's open-source transport). One side Listens, the others Connect; messages are sent on a NetConnection. There is no replication here: what is sent, and what it means, is the game's. Without the library, IsActive is false and every call does nothing, so a game that can also play alone works the same.
Objects of this class are refused to mods.
Properties¶
is_active: booleanTrue when the library started: connections can be made. False means every call does nothing. Read-only.status: stringWhy the system is not active, or "Ready.". Read-only.listening_port: numberThe port being listened on (the one asked for, or the free one the library chose), or 0. Read-only.
Signals¶
connection_requested: Signal<NetConnection, string>Somebody wants to connect to the port we listen on, with their address. The connection is accepted when the handlers return, unless one of them called NetConnection.Refuse. Messages cannot be sent on it yet: wait for Connected.connected: Signal<NetConnection>A connection is up: the one that Connect started was accepted, or a requested one is made. Messages can be sent now.disconnected: Signal<NetConnection, string, number>A connection ended: the other side closed it, it timed out, or a connection that was being made failed. With the reason's text and code (1000 and up: the other side's own).message: Signal<NetConnection, string, number>A message arrived on a connection, as text, on a lane.
Methods¶
listen¶
function listen(self, port: number?): number
Listens on a UDP port, for IPv4 and IPv6 (0: any free port). Returns the port, or 0 if it could not be opened (it is in use, or the system is inactive). One port at a time: listening again closes the first (its connections stay).
stop_listening¶
function stop_listening(self): ()
Stops accepting new connections; the ones made stay.
connect¶
function connect(self, address: string): NetConnection?
Starts connecting to host:port (an IP address, [::1]:27020 for IPv6, or a name, which is looked up first and so can block for a moment). The result is a Connected or a Disconnected signal. Returns null when the address cannot be used.
update¶
function update(self): ()
Once a frame: runs the library's callbacks and emits what happened as signals, in order: connections made, messages, connections ended.
Functions¶
create¶
NetSystem.create: () -> NetSystem
Makes a network system of its own from a script: for tests, which talk to themselves over the loopback interface. A game's own is the global net.
create_inactive¶
NetSystem.create_inactive: () -> NetSystem
Makes an inactive network system from a script: for tests of what scripts see when there is no library.
is_installed¶
NetSystem.is_installed: () -> boolean
Whether the library can be loaded: false on a machine without GameNetworkingSockets next to the program.