class Network

Inherits: Module<Network>

High-level networking class that wraps NetworkPeer to provide simple server/client functionality.

This is a convenience wrapper around NetworkPeer for applications that need basic networking without manual peer management. For Phase 1.1, this class provides only basic hosting/connecting functionality. High-level features like entity replication will be added in future phases.

Example usage as server:

Example usage as client:

For full control over networking, use NetworkPeer directly instead of this wrapper.

Public

Methods

IsHost

bool IsHost() const

Checks if this instance is currently hosting a server.

Returns: True if hosting, false otherwise.

IsClient

bool IsClient() const

Checks if this instance is a connected or connecting client.

Returns: True if client connection is active or being established, false otherwise.

Host

void Host(u16 port, u32 maxConnections = 64)

Starts hosting a server on the specified port.

port
Port to listen on for incoming connections.
maxConnections
Maximum number of simultaneous client connections allowed.

Connect

void Connect(const char *host, u16 port)

Connects to a remote server.

host
Hostname or IP address of the server (e.g., "127.0.0.1" or "example.com").
port
Port of the server to connect to.

Disconnect

void Disconnect()

Disconnects from the current network session (server or client).

Update

void Update(float dt)

Updates the network system.

Currently a stub for Phase 1.1.

dt
Time elapsed since last update, in seconds.

staticInstance

static T &Instance()

Returns a reference to the module instance.

Module has to have been started up first otherwise an exception will be thrown.

staticInstancePtr

static T *InstancePtr()

Returns a pointer to the module instance.

Module has to have been started up first otherwise an exception will be thrown.

staticShutDown

static void ShutDown()

Shuts down this module and frees any resources it is using.

staticIsStarted

static bool IsStarted()

Query if the module has been started.

Protected

Methods

~Module<T>

virtual ~Module<T>() = default

OnStartUp

virtual void OnStartUp()

Override if you want your module to be notified once it has been constructed and started.

OnShutDown

virtual void OnShutDown()

Override if you want your module to be notified just before it is deleted.

staticInstanceInternal

static T *&InstanceInternal()

Returns a singleton instance of this module.

staticIsDestroyed

static bool &IsDestroyed()

Checks has the Module been shut down.

staticIsStartedUp

static bool &IsStartedUp()

Checks has the Module been started up.

Private

Fields

mState

mPeer

UPtr<NetworkPeer> mPeer