NetConnectionManager class

Public static functions

static void OnConnectionStatusChanged(SteamNetConnectionStatusChangedCallback_t* info)
GNS status callback — routes into this manager. Must be static for GNS.

Constructors, destructors, conversion operators

NetConnectionManager() defaulted
~NetConnectionManager()

Public functions

void Initialize(GNSContext* gns)
Bind to GNS context. Must be called before Listen/Connect.
void Shutdown()
auto Listen(uint16_t port) -> bool
Start listening on the given port. Returns true on success.
void StopListening()
Stop listening and close all connections.
void AcceptConnection(HSteamNetConnection conn)
Accept a pending connection (called from status callback context).
auto Connect(const char* address, uint16_t port) -> HSteamNetConnection
Connect to a remote server. Returns the GNS connection handle (0 on failure).
void CloseConnection(HSteamNetConnection conn, const char* reason = "Closed")
Close a specific connection.
auto PollIncoming(std::vector<ReceivedMessage>& outMessages) -> int
auto Send(HSteamNetConnection conn, const PacketHeader& header, const uint8_t* payload, bool reliable = false, bool noNagle = false) -> bool
Send a header + payload to a specific connection. Returns true on success.
auto SendPrebuilt(HSteamNetConnection conn, const PacketHeader& header, const uint8_t* payload, bool noNagle = false) -> bool
auto SendRaw(HSteamNetConnection conn, const uint8_t* data, uint32_t size, bool reliable = false, bool noNagle = false) -> bool
Send raw bytes (header already serialized into buffer).
void SetNoNagle(bool enabled)
void SetSendRate(int minBytesPerSec, int maxBytesPerSec)
void RunCallbacks()
auto FindConnection(HSteamNetConnection conn) -> ConnectionInfo*
Find connection info by GNS handle. Returns nullptr if not found.
auto FindConnectionByOwnerID(uint8_t ownerID, bool requireServerSide = false) -> ConnectionInfo*
auto GetConnections() const -> const std::list<ConnectionInfo>&
Get all active connections.
auto GetConnections() -> std::list<ConnectionInfo>&
auto GetConnectionCount() const -> int
Number of active connections.
void AssignOwnerID(HSteamNetConnection conn, uint8_t ownerID)
Assign a NetOwnerID to a connection.
void GenerateNetID(HSteamNetConnection conn)
Generate and Assign a NetOwnerID to a connection. Called during handshake.
auto GetLocalOwnerID() const -> uint8_t

Public variables

OnClientConnectedEvent OnClientConnected
OnClientDisconnectedEvent OnClientDisconnected

Function documentation

int NetConnectionManager::PollIncoming(std::vector<ReceivedMessage>& outMessages)

Poll GNS for incoming messages on all connections. Appends to outMessages. Returns number of messages received.

bool NetConnectionManager::SendPrebuilt(HSteamNetConnection conn, const PacketHeader& header, const uint8_t* payload, bool noNagle = false)

Send a pre-built header (sequence already stamped by Sentinel) + payload. Use from job workers — does NOT touch NextSeqOut on ConnectionInfo.

void NetConnectionManager::SetNoNagle(bool enabled)

Force NoNagle on all unreliable sends from this manager. Equivalent to the EngineConfig::NoNagle setting. Safe to call before Start().

void NetConnectionManager::SetSendRate(int minBytesPerSec, int maxBytesPerSec)

Set GNS per-connection send rate (bytes/sec). Applied to every connection at Connect/Accept time. -1 = leave GNS default (256KB/s). Set both min and max to the same value to pin the rate.

void NetConnectionManager::RunCallbacks()

Run GNS internal callbacks (connection status changes, etc.). Must be called regularly from the polling thread.

ConnectionInfo* NetConnectionManager::FindConnectionByOwnerID(uint8_t ownerID, bool requireServerSide = false)

Find connection info by OwnerID. Returns nullptr if not found. O(n) over active connections — only use outside hot-path code. In PIE, two ConnectionInfo entries share the same OwnerID (bAuthoritySide and bOwnerInitiated). Pass requireServerSide=true to get the server-accepted leg.

uint8_t NetConnectionManager::GetLocalOwnerID() const

The OwnerID assigned to this process's own client-initiated connection. Set atomically in AssignOwnerID when the connection is client-initiated. Safe to poll from any thread — 0 means not yet assigned. Available in testing and editor builds only.

Variable documentation

OnClientConnectedEvent NetConnectionManager::OnClientConnected

Fired when a server-side connection is fully confirmed (GNS handshake complete). Fires on the NetThread during RunCallbacks(). Safe to call World::Spawn() from here.

OnClientDisconnectedEvent NetConnectionManager::OnClientDisconnected

Fired when a server-side connection closes (ClosedByPeer or ProblemDetectedLocally). ownerID is 0 if the client disconnected before completing the handshake.