Class NetworkManager
The network manager drives the NetworkClient and NetworkServer systems.
TODO: Make extensible with Justin's NetworkLogic idea.
Namespace: FNNLib
Assembly: FNNLib.dll
Syntax
public class NetworkManager : MonoBehaviour
Fields
| Improve this Doc View SourceallClientIDs
List of all client IDs
Declaration
public List<ulong> allClientIDs
Field Value
| Type | Description |
|---|---|
| List<UInt64> |
clientOnConnect
On client connects to server.
Declaration
public UnityEvent clientOnConnect
Field Value
| Type | Description |
|---|---|
| UnityEvent |
clientOnDisconnect
On client disconnects from server.
Declaration
public UnityEvent<string> clientOnDisconnect
Field Value
| Type | Description |
|---|---|
| UnityEvent<String> |
connectedClients
Dictionary containing all connected clients. Key is client ID.
Declaration
public readonly Dictionary<ulong, NetworkedClient> connectedClients
Field Value
| Type | Description |
|---|---|
| Dictionary<UInt64, NetworkedClient> |
connectedClientsList
List of all connected clients.
Declaration
public readonly List<NetworkedClient> connectedClientsList
Field Value
| Type | Description |
|---|---|
| List<NetworkedClient> |
connectionApprovalCallback
Connection approval callback. Used for adding extra logic to connection acceptance.
Declaration
public ApproveConnectionDelegate connectionApprovalCallback
Field Value
| Type | Description |
|---|---|
| ApproveConnectionDelegate |
dontDestroyOnLoad
Whether or not to move the manager to the DontDestroyOnLoad Scene.
Declaration
public bool dontDestroyOnLoad
Field Value
| Type | Description |
|---|---|
| Boolean |
instance
The game's NetworkManager.
Declaration
public static NetworkManager instance
Field Value
| Type | Description |
|---|---|
| NetworkManager |
networkConfig
The network config.
Declaration
public NetworkConfig networkConfig
Field Value
| Type | Description |
|---|---|
| NetworkConfig |
runInBackground
Whether or not the application should run in the background while networking is running. Will be reset once the client/server is finished.
Declaration
public bool runInBackground
Field Value
| Type | Description |
|---|---|
| Boolean |
ServerLocalID
The local ID of the server
Declaration
public const ulong ServerLocalID = 0UL
Field Value
| Type | Description |
|---|---|
| UInt64 |
serverOnClientConnect
On client connect to server.
Declaration
public UnityEvent<ulong> serverOnClientConnect
Field Value
| Type | Description |
|---|---|
| UnityEvent<UInt64> |
serverOnClientDisconnect
On client disconnect from server.
Declaration
public UnityEvent<ulong> serverOnClientDisconnect
Field Value
| Type | Description |
|---|---|
| UnityEvent<UInt64> |
Properties
| Improve this Doc View SourceisClient
Whether or not the game should run clientside code.
Declaration
public bool isClient { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
isHost
Whether or not the client is a virtual client.
Declaration
public bool isHost { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
isServer
Whether or not the game should run serverside code.
Declaration
public bool isServer { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
isSinglePlayer
Whether or not the game is running in single player mode.
Declaration
public bool isSinglePlayer { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
localClientID
The local client ID.
Declaration
public ulong localClientID { get; }
Property Value
| Type | Description |
|---|---|
| UInt64 |
Methods
| Improve this Doc View SourceConfigureServerFramerate()
Configure the server's framerate to prevent high CPU usage.
Declaration
protected virtual void ConfigureServerFramerate()
ServerDisconnect(UInt64, String)
Disconnect a client with a reason
Declaration
public void ServerDisconnect(ulong clientID, string disconnectReason)
Parameters
| Type | Name | Description |
|---|---|---|
| UInt64 | clientID | |
| String | disconnectReason |
ServerForceDisconnect(UInt64)
Disconnect a client without a reason.
Declaration
public void ServerForceDisconnect(ulong clientID)
Parameters
| Type | Name | Description |
|---|---|---|
| UInt64 | clientID | Client to disconnect. |
SinglePlayerStartHost()
Converts single player game to host game.
Declaration
public void SinglePlayerStartHost()
StartClient(String, Byte[])
Start the manager in client mode.
Declaration
public void StartClient(string hostname, byte[] connectionRequestData = null)
Parameters
| Type | Name | Description |
|---|---|---|
| String | hostname | The hostname of the server to connect to. |
| Byte[] | connectionRequestData | Connection request data used for the approval stage. |
Exceptions
| Type | Condition |
|---|---|
| NotSupportedException |
StartHost()
Start the manager in host mode. This runs a virtual client on top of the server.
Declaration
public void StartHost()
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | |
| NotSupportedException |
StartServer()
Starts the manager in server mode.
Declaration
public void StartServer()
StartSinglePlayer()
Runs the game as if there was a server, without running one.
Declaration
public void StartSinglePlayer()
StopClient()
Stop the client
Declaration
public void StopClient()
Exceptions
| Type | Condition |
|---|---|
| NotSupportedException | Thrown if running in a different mode, or a client isn't running. |
StopHost()
Stop host mode, closing the server and disconnecting remote users.
Declaration
public void StopHost()
Exceptions
| Type | Condition |
|---|---|
| NotSupportedException |
StopServer()
Stop a running server.
Declaration
public void StopServer()
Exceptions
| Type | Condition |
|---|---|
| NotSupportedException |
StopSinglePlayer()
Stops running the game in single player mode.
Declaration
public void StopSinglePlayer()