Noble Connect
Add relays and punchthrough to Mirror or UNet
NobleConnect.Mirror.NobleServer Class Reference

Adds relay, punchthrough, and port-forwarding support to the Mirror NetworkServer More...

Static Public Member Functions

static void InitializeHosting (int listenPort, GeographicRegion region=GeographicRegion.AUTO, Action< string, ushort > onPrepared=null, Action< string > onFatalError=null, bool forceRelayOnly=false)
 Initialize the server using NobleConnectSettings. The region used is determined by the Relay Server Address in the NobleConnectSettings. More...
 
static void InitializeHosting (int listenPort, string relayServerAddress, Action< string, ushort > onPrepared=null, Action< string > onFatalError=null, bool forceRelayOnly=false)
 Initialize the client using NobleConnectSettings but connect to specific relay server address. This method is useful for selecting the region to connect to at run time when starting the client. More...
 
static void Update ()
 If you are using the NetworkServer directly you must call this method every frame. More...
 
static void Listen (int port=0, GeographicRegion region=GeographicRegion.AUTO, Action< string, ushort > onPrepared=null, Action< string > onFatalError=null, bool forceRelayOnly=false)
 Start listening for incoming connections More...
 
static void SetListenPort (ushort port)
 
static ushort GetTransportPort ()
 
static void SetTransportPort (ushort port)
 
static void UnregisterHandler< T > ()
 
static void ClearHandlers ()
 
static void Dispose ()
 Clean up and free resources. Called automatically when garbage collected. More...
 
static void OnServerConnect (NetworkConnection conn)
 
static void OnServerDisconnect (NetworkConnection conn)
 Called on the server when a client disconnects More...
 
static void Shutdown ()
 
static void SendToAll< T > (T msg, int channelId=Channels.DefaultReliable, bool sendToReadyOnly=false)
 
static void SendToReady< T > (NetworkIdentity identity, T msg, bool includeSelf=true, int channelId=Channels.DefaultReliable)
 
static void SendToReady< T > (NetworkIdentity identity, T msg, int channelId=Channels.DefaultReliable)
 
static void DisconnectAll ()
 
static void SendToClientOfPlayer< T > (NetworkIdentity player, T msg)
 
static bool ReplacePlayerForConnection (NetworkConnection conn, GameObject player, Guid assetId, bool keepAuthority=false)
 
static bool ReplacePlayerForConnection (NetworkConnection conn, GameObject player, bool keepAuthority=false)
 
static bool AddPlayerForConnection (NetworkConnection conn, GameObject player, Guid assetId)
 
static bool AddPlayerForConnection (NetworkConnection conn, GameObject player)
 
static void SetClientReady (NetworkConnection conn)
 
static void SetAllClientsNotReady ()
 
static void SetClientNotReady (NetworkConnection conn)
 
static void DestroyPlayerForConnection (NetworkConnection conn)
 
static void Spawn (GameObject obj)
 
static void Spawn (GameObject obj, GameObject player)
 
static void Spawn (GameObject obj, NetworkConnection conn)
 
static void Spawn (GameObject obj, Guid assetId, NetworkConnection conn)
 
static void Spawn (GameObject obj, Guid assetId)
 
static void Destroy (GameObject obj)
 
static void UnSpawn (GameObject obj)
 
static NetworkIdentity FindLocalObject (uint netId)
 
static bool SpawnObjects ()
 

Static Public Attributes

static float allocationResendTimeout = .1f
 Initial timeout before resending refresh messages. This is doubled for each failed resend. More...
 
static float requestTimeout = .2f
 Request timeout. More...
 
static int maxAllocationResends = 8
 Max number of times to try and resend refresh messages before giving up and shutting down the relay connection. More...
 
static int relayLifetime = 60
 How long a relay will stay alive without being refreshed (in seconds) More...
 
static int relayRefreshTime = 30
 How often to refresh the relay to keep it alive, in seconds More...
 

Properties

static IPEndPoint HostEndPoint [get, set]
 This is the address that clients should connect to. It is assigned by the relay server. More...
 
static NetworkConnection localConnection [get]
 
static Dictionary< int, NetworkConnectionToClient > connections [get]
 
static bool dontListen [get, set]
 
static bool active [get]
 
static bool localClientActive [get]
 

Detailed Description

Adds relay, punchthrough, and port-forwarding support to the Mirror NetworkServer

Use the Listen method to start listening for incoming connections.

Member Function Documentation

◆ AddPlayerForConnection() [1/2]

static bool NobleConnect.Mirror.NobleServer.AddPlayerForConnection ( NetworkConnection  conn,
GameObject  player 
)
static

◆ AddPlayerForConnection() [2/2]

static bool NobleConnect.Mirror.NobleServer.AddPlayerForConnection ( NetworkConnection  conn,
GameObject  player,
Guid  assetId 
)
static

◆ ClearHandlers()

static void NobleConnect.Mirror.NobleServer.ClearHandlers ( )
static

◆ Destroy()

static void NobleConnect.Mirror.NobleServer.Destroy ( GameObject  obj)
static

◆ DestroyPlayerForConnection()

static void NobleConnect.Mirror.NobleServer.DestroyPlayerForConnection ( NetworkConnection  conn)
static

◆ DisconnectAll()

static void NobleConnect.Mirror.NobleServer.DisconnectAll ( )
static

◆ Dispose()

static void NobleConnect.Mirror.NobleServer.Dispose ( )
static

Clean up and free resources. Called automatically when garbage collected.

You shouldn't need to call this directly. It will be called automatically when an unused NobleServer is garbage collected or when shutting down the application.

Parameters
disposing

◆ FindLocalObject()

static NetworkIdentity NobleConnect.Mirror.NobleServer.FindLocalObject ( uint  netId)
static

◆ GetTransportPort()

static ushort NobleConnect.Mirror.NobleServer.GetTransportPort ( )
static

◆ InitializeHosting() [1/2]

static void NobleConnect.Mirror.NobleServer.InitializeHosting ( int  listenPort,
GeographicRegion  region = GeographicRegion.AUTO,
Action< string, ushort >  onPrepared = null,
Action< string >  onFatalError = null,
bool  forceRelayOnly = false 
)
static

Initialize the server using NobleConnectSettings. The region used is determined by the Relay Server Address in the NobleConnectSettings.

Parameters
topoThe HostTopology to use for the NetworkClient. Must be the same on host and client.
onFatalErrorA method to call if something goes horribly wrong.

◆ InitializeHosting() [2/2]

static void NobleConnect.Mirror.NobleServer.InitializeHosting ( int  listenPort,
string  relayServerAddress,
Action< string, ushort >  onPrepared = null,
Action< string >  onFatalError = null,
bool  forceRelayOnly = false 
)
static

Initialize the client using NobleConnectSettings but connect to specific relay server address. This method is useful for selecting the region to connect to at run time when starting the client.

Parameters
relayServerAddressThe url or ip of the relay server to connect to
topoThe HostTopology to use for the NetworkClient. Must be the same on host and client.
onPreparedA method to call when the host has received their HostEndPoint from the relay server.
onFatalErrorA method to call if something goes horribly wrong.

◆ Listen()

static void NobleConnect.Mirror.NobleServer.Listen ( int  port = 0,
GeographicRegion  region = GeographicRegion.AUTO,
Action< string, ushort >  onPrepared = null,
Action< string >  onFatalError = null,
bool  forceRelayOnly = false 
)
static

Start listening for incoming connections

Parameters
maxPlayersThe maximum number of players
portThe port to listen on. Defaults to 0 which will use a random port
onPreparedA method to call when the host has received their HostEndPoint from the relay server.

◆ OnServerConnect()

static void NobleConnect.Mirror.NobleServer.OnServerConnect ( NetworkConnection  conn)
static

◆ OnServerDisconnect()

static void NobleConnect.Mirror.NobleServer.OnServerDisconnect ( NetworkConnection  conn)
static

Called on the server when a client disconnects

Some memory and ports are freed here.

Parameters
message

◆ ReplacePlayerForConnection() [1/2]

static bool NobleConnect.Mirror.NobleServer.ReplacePlayerForConnection ( NetworkConnection  conn,
GameObject  player,
bool  keepAuthority = false 
)
static

◆ ReplacePlayerForConnection() [2/2]

static bool NobleConnect.Mirror.NobleServer.ReplacePlayerForConnection ( NetworkConnection  conn,
GameObject  player,
Guid  assetId,
bool  keepAuthority = false 
)
static

◆ SendToAll< T >()

static void NobleConnect.Mirror.NobleServer.SendToAll< T > ( msg,
int  channelId = Channels.DefaultReliable,
bool  sendToReadyOnly = false 
)
static
Type Constraints
T :struct 
T :NetworkMessage 

◆ SendToClientOfPlayer< T >()

static void NobleConnect.Mirror.NobleServer.SendToClientOfPlayer< T > ( NetworkIdentity  player,
msg 
)
static
Type Constraints
T :struct 
T :NetworkMessage 

◆ SendToReady< T >() [1/2]

static void NobleConnect.Mirror.NobleServer.SendToReady< T > ( NetworkIdentity  identity,
msg,
bool  includeSelf = true,
int  channelId = Channels.DefaultReliable 
)
static
Type Constraints
T :struct 
T :NetworkMessage 

◆ SendToReady< T >() [2/2]

static void NobleConnect.Mirror.NobleServer.SendToReady< T > ( NetworkIdentity  identity,
msg,
int  channelId = Channels.DefaultReliable 
)
static
Type Constraints
T :struct 
T :NetworkMessage 

◆ SetAllClientsNotReady()

static void NobleConnect.Mirror.NobleServer.SetAllClientsNotReady ( )
static

◆ SetClientNotReady()

static void NobleConnect.Mirror.NobleServer.SetClientNotReady ( NetworkConnection  conn)
static

◆ SetClientReady()

static void NobleConnect.Mirror.NobleServer.SetClientReady ( NetworkConnection  conn)
static

◆ SetListenPort()

static void NobleConnect.Mirror.NobleServer.SetListenPort ( ushort  port)
static

◆ SetTransportPort()

static void NobleConnect.Mirror.NobleServer.SetTransportPort ( ushort  port)
static

◆ Shutdown()

static void NobleConnect.Mirror.NobleServer.Shutdown ( )
static

◆ Spawn() [1/5]

static void NobleConnect.Mirror.NobleServer.Spawn ( GameObject  obj)
static

◆ Spawn() [2/5]

static void NobleConnect.Mirror.NobleServer.Spawn ( GameObject  obj,
GameObject  player 
)
static

◆ Spawn() [3/5]

static void NobleConnect.Mirror.NobleServer.Spawn ( GameObject  obj,
Guid  assetId 
)
static

◆ Spawn() [4/5]

static void NobleConnect.Mirror.NobleServer.Spawn ( GameObject  obj,
Guid  assetId,
NetworkConnection  conn 
)
static

◆ Spawn() [5/5]

static void NobleConnect.Mirror.NobleServer.Spawn ( GameObject  obj,
NetworkConnection  conn 
)
static

◆ SpawnObjects()

static bool NobleConnect.Mirror.NobleServer.SpawnObjects ( )
static

◆ UnregisterHandler< T >()

static void NobleConnect.Mirror.NobleServer.UnregisterHandler< T > ( )
static
Type Constraints
T :struct 
T :NetworkMessage 

◆ UnSpawn()

static void NobleConnect.Mirror.NobleServer.UnSpawn ( GameObject  obj)
static

◆ Update()

static void NobleConnect.Mirror.NobleServer.Update ( )
static

If you are using the NetworkServer directly you must call this method every frame.

The NobleNetworkManager and NobleNetworkLobbyManager handle this for you but you if you are using the NobleServer directly you must make sure to call this method every frame.

Member Data Documentation

◆ allocationResendTimeout

float NobleConnect.Mirror.NobleServer.allocationResendTimeout = .1f
static

Initial timeout before resending refresh messages. This is doubled for each failed resend.

◆ maxAllocationResends

int NobleConnect.Mirror.NobleServer.maxAllocationResends = 8
static

Max number of times to try and resend refresh messages before giving up and shutting down the relay connection.

If refresh messages fail for 30 seconds the relay connection will be closed remotely regardless of these settings.

◆ relayLifetime

int NobleConnect.Mirror.NobleServer.relayLifetime = 60
static

How long a relay will stay alive without being refreshed (in seconds)

Setting this value higher means relays will stay alive longer even if the host temporarily loses connection or otherwise fails to send the refresh request in time. This can be helpful to maintain connection on an undependable network or when heavy application load (such as loading large levels synchronously) temporarily prevents requests from being processed. The drawback is that CCU is used for as long as the relay stays alive, so players that crash or otherwise don't clean up properly can cause lingering CCU usage for up to relayLifetime seconds.

◆ relayRefreshTime

int NobleConnect.Mirror.NobleServer.relayRefreshTime = 30
static

How often to refresh the relay to keep it alive, in seconds

◆ requestTimeout

float NobleConnect.Mirror.NobleServer.requestTimeout = .2f
static

Request timeout.

This effects how long to wait before considering a request to have failed. Requests are used during the punchthrough process and for setting up and maintaining relays. If you are allowing cross-region play or expect high latency you can increase this so that requests won't time out. The drawback is that waiting longer for timeouts causes it take take longer to detect actual failed requests so the connection process may take longer.

Property Documentation

◆ active

bool NobleConnect.Mirror.NobleServer.active
staticget

◆ connections

Dictionary<int, NetworkConnectionToClient> NobleConnect.Mirror.NobleServer.connections
staticget

◆ dontListen

bool NobleConnect.Mirror.NobleServer.dontListen
staticgetset

◆ HostEndPoint

IPEndPoint NobleConnect.Mirror.NobleServer.HostEndPoint
staticgetset

This is the address that clients should connect to. It is assigned by the relay server.

Note that this is not the host's actual IP address, but one assigned to the host by the relay server. When clients connect to this address, Noble Connect will find the best possible connection and use it. This means that the client may actually end up connecting to an address on the local network, or an address on the router, or an address on the relay. But you don't need to worry about any of that, it is all handled for you internally.

◆ localClientActive

bool NobleConnect.Mirror.NobleServer.localClientActive
staticget

◆ localConnection

NetworkConnection NobleConnect.Mirror.NobleServer.localConnection
staticget