menu_bookDocumentation

Networking Static Class: IsHost, IsClient, CreateLobby, Connect, SetData, and Debug Convars

calendar_today May 4, 2026 schedule ~1 min read person patrickjr verified 50

Networking Static Class: IsHost, IsClient, CreateLobby, Connect, and Server Data

The Networking static class manages the multiplayer session in s&box.

Session State

CSHARP
Networking.IsHost       // true if we're the host (or not connected)
Networking.IsClient     // true if connected to a server and NOT the host
Networking.IsActive     // true if a network session exists
Networking.IsConnecting // true if currently connecting

Note: Networking.IsHost returns true when not connected at all (no NetworkSystem). Always check Networking.IsActive first if you need to distinguish "offline" from "hosting".

Creating a Lobby

CSHARP
// Create a lobby with config
Networking.CreateLobby( new LobbyConfig
{
    MaxPlayers = 16,
    Name = "My Server",
    Privacy = LobbyPrivacy.Public
} );

Connecting

CSHARP
// Connect by SteamId (lobby or player)
Networking.Connect( steamId );

// Connect by IP:port
Networking.Connect( "192.168.1.1:27015" );

// Connect to local editor session
Networking.Connect( "local" );

// Disconnect
Networking.Disconnect();

Server Data (Lobby Metadata)

CSHARP
// Set data visible to players browsing servers
Networking.SetData( "gamemode", "deathmatch" );
Networking.SetData( "map", "de_dust2" );

// Get data
string mode = Networking.GetData( "gamemode" );

Server data is propagated to all connected clients via ServerDataMsg and is also visible in lobby queries.

Server Name and Map

CSHARP
Networking.ServerName = "My Awesome Server";
Networking.MapName = "de_dust2";  // internal, set by the engine

Interpolation Time

CSHARP
// net_interp_time convar (default 0.1s)
// Controls how far behind real-time proxies are interpolated
Networking.InterpolationTime  // 0.1f by default

Debug Convars

CSHARP
// Simulate packet loss (cheat-protected)
// net_fakepacketloss 10  → 10% packet loss

// Simulate latency (cheat-protected)
// net_fakelag 100  → 100ms added latency

HostStats

CSHARP
var stats = Networking.HostStats;
// stats.InBytesPerSecond, stats.OutBytesPerSecond, stats.Ping
Was this helpful?