Class NetworkManager
High-level networking manager for multiplayer games.
Inheritance
Namespace: FlaxEngine.Networking
Assembly: FlaxEngine.CSharp.dll
Syntax
[Unmanaged]
public static class NetworkManager : Object
Fields
ServerClientId
Server client identifier. Constant value of 0.
Declaration
[Unmanaged]
public const uint ServerClientId = 0U
Field Value
System.UInt32
|
Properties
Clients
List of all clients: connecting, connected and disconnected. Empty on clients.
Declaration
[Unmanaged]
public static NetworkClient[] Clients { get; }
Property Value
NetworkClient[]
|
Frame
Current network system frame number (incremented every tick). Can be used for frames counting in networking and replication.
Declaration
[Unmanaged]
public static uint Frame { get; }
Property Value
System.UInt32
|
IsClient
Returns true if network is a client.
Declaration
[Unmanaged]
public static bool IsClient { get; }
Property Value
System.Boolean
|
IsConnected
Returns true if network is connected and online.
Declaration
[Unmanaged]
public static bool IsConnected { get; }
Property Value
System.Boolean
|
IsHost
Returns true if network is a host (both client and server).
Declaration
[Unmanaged]
public static bool IsHost { get; }
Property Value
System.Boolean
|
IsOffline
Returns true if network is online or disconnected.
Declaration
[Unmanaged]
public static bool IsOffline { get; }
Property Value
System.Boolean
|
IsServer
Returns true if network is a server.
Declaration
[Unmanaged]
public static bool IsServer { get; }
Property Value
System.Boolean
|
LocalClient
Local client, valid only when Network Manager is running in client or host mode (server doesn't have a client).
Declaration
[Unmanaged]
public static NetworkClient LocalClient { get; }
Property Value
NetworkClient
|
LocalClientId
Local client identifier. Valid even on server that doesn't have LocalClient.
Declaration
[Unmanaged]
public static uint LocalClientId { get; }
Property Value
System.UInt32
|
Mode
Current manager mode.
Declaration
[Unmanaged]
public static NetworkManagerMode Mode { get; }
Property Value
NetworkManagerMode
|
NetworkFPS
The target amount of the network logic updates per second (frequency of replication, events sending and network ticking). Use 0 to run every game update.
Declaration
[Unmanaged]
public static float NetworkFPS { get; set; }
Property Value
System.Single
|
Peer
Current network peer (low-level).
Declaration
[Unmanaged]
public static NetworkPeer Peer { get; }
Property Value
NetworkPeer
|
State
Current network connection state.
Declaration
[Unmanaged]
public static NetworkConnectionState State { get; }
Property Value
NetworkConnectionState
|
Methods
add_ClientConnecting(NetworkManager.ClientConnectingDelegate)
Declaration
public static void add_ClientConnecting(NetworkManager.ClientConnectingDelegate value)
Parameters
NetworkManager.ClientConnectingDelegate
value
|
GetClient(ref NetworkConnection)
Gets the network client for a given connection. Returns null if failed to find it.
Declaration
[Unmanaged]
public static NetworkClient GetClient(ref NetworkConnection connection)
Parameters
NetworkConnection
connection
Network connection identifier. |
Returns
NetworkClient
Found client or null. |
GetClient(UInt32)
Gets the network client with a given identifier. Returns null if failed to find it.
Declaration
[Unmanaged]
public static NetworkClient GetClient(uint clientId)
Parameters
System.UInt32
clientId
Network client identifier (synchronized on all peers). |
Returns
NetworkClient
Found client or null. |
remove_ClientConnecting(NetworkManager.ClientConnectingDelegate)
Declaration
public static void remove_ClientConnecting(NetworkManager.ClientConnectingDelegate value)
Parameters
NetworkManager.ClientConnectingDelegate
value
|
StartClient()
Starts the network in client mode. Returns true if failed (eg. invalid config).
Declaration
[Unmanaged]
public static bool StartClient()
Returns
System.Boolean
|
StartHost()
Starts the network in host mode. Returns true if failed (eg. invalid config).
Declaration
[Unmanaged]
public static bool StartHost()
Returns
System.Boolean
|
StartServer()
Starts the network in server mode. Returns true if failed (eg. invalid config).
Declaration
[Unmanaged]
public static bool StartServer()
Returns
System.Boolean
|
Stop()
Stops the network.
Declaration
[Unmanaged]
public static void Stop()
Events
ClientConnected
Event called after new client successfully connected.
Declaration
[Unmanaged]
public static event Action<NetworkClient> ClientConnected
Event Type
System.Action<NetworkClient>
|
ClientConnecting
Event called when new client is connecting. Can be used to accept/deny connection. Called on client to fill PayloadData send and called on server/host to validate incoming client connection (eg. with PayloadData validation).
Declaration
[Unmanaged]
public static event NetworkManager.ClientConnectingDelegate ClientConnecting
Event Type
NetworkManager.ClientConnectingDelegate
|
ClientDisconnected
Event called after new client successfully disconnected.
Declaration
[Unmanaged]
public static event Action<NetworkClient> ClientDisconnected
Event Type
System.Action<NetworkClient>
|
StateChanged
Event called when network manager state gets changed (eg. client connected to the server, or server shutdown started).
Declaration
[Unmanaged]
public static event Action StateChanged
Event Type
System.Action
|