Skip to content

Class NetSystem

Namespace: Apogee.Network
Assembly: Apogee.Network.dll

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 s, the others ; messages are sent on a . There is no replication here: what is sent, and what it means, is the game's. Without the library, is false and every call does nothing, so a game that can also play alone works the same.

public sealed class NetSystem : EngineObject, IDisposable

Inheritance

object ← EngineObject ← NetSystem

Implements

IDisposable

Inherited Members

EngineObject.IsAdopted, EngineObject.Handle, EngineObject.IsDestroyed, EngineObject.Class, EngineObject.Adopt(), EngineObject.TryGet(SlotHandle, out EngineObject), EngineObject.Destroy(), object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks

Call once a frame: it runs the library's callbacks and turns what happened into signals, all on the calling thread (nothing of the game runs on the library's threads). Mods cannot use this object: it is the game's. Messages reach scripts as text (UTF-8, such as JSON); C# can also send and receive bytes.

Constructors

NetSystem(NetOptions?)

Starts the library. If it cannot be started the system is inactive, says why, and the reason is logged once.

public NetSystem(NetOptions? options = null)

Parameters

options NetOptions?

Properties

Class

What the registry knows about this object's class.

public override ClassInfo Class { get; }

Property Value

ClassInfo

Connected

A connection is up: the one that started was accepted, or a requested one is made. Messages can be sent now.

public Signal<NetConnection> Connected { get; }

Property Value

Signal<NetConnection>

ConnectionRequested

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 . Messages cannot be sent on it yet: wait for .

public Signal<NetConnection, string> ConnectionRequested { get; }

Property Value

Signal<NetConnection, string>

Disconnected

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).

public Signal<NetConnection, string, int> Disconnected { get; }

Property Value

Signal<NetConnection, string, int>

IsActive

True when the library started: connections can be made. False means every call does nothing.

public bool IsActive { get; }

Property Value

bool

ListeningPort

The port being listened on (the one asked for, or the free one the library chose), or 0.

public int ListeningPort { get; }

Property Value

int

Message

A message arrived on a connection, as text, on a lane.

public Signal<NetConnection, string, int> Message { get; }

Property Value

Signal<NetConnection, string, int>

Status

Why the system is not active, or "Ready.".

public string Status { get; }

Property Value

string

Methods

Connect(string)

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 or a signal. Returns null when the address cannot be used.

public NetConnection? Connect(string address)

Parameters

address string

Returns

NetConnection?

Create()

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.

public static NetSystem Create()

Returns

NetSystem

CreateInactive()

Makes an inactive network system from a script: for tests of what scripts see when there is no library.

public static NetSystem CreateInactive()

Returns

NetSystem

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

IsInstalled()

Whether the library can be loaded: false on a machine without GameNetworkingSockets next to the program.

public static bool IsInstalled()

Returns

bool

Listen(int)

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).

public int Listen(int port = 0)

Parameters

port int

Returns

int

OnDestroyed()

protected override void OnDestroyed()

StopListening()

Stops accepting new connections; the ones made stay.

public void StopListening()

Update()

Once a frame: runs the library's callbacks and emits what happened as signals, in order: connections made, messages, connections ended.

public void Update()

BytesReceived

A message arrived, as bytes: for C#, which can send and receive anything. Called before .

public event Action<NetConnection, byte[], int>? BytesReceived

Event Type

Action<NetConnection, byte[], int>?