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

A NetworkManager that utilizes the Noble Connect relay and punchthrough services More...

Inherits NetworkManager.

Inherited by NobleConnect.UNet.NobleNetworkLobbyManager.

Public Member Functions

virtual void Awake ()
 Initialize connectionConfig and HostTopology plus some other important setup. More...
 
virtual void Start ()
 
virtual void Update ()
 Updates the NobleClient and NobleServer. More...
 
void InitClient ()
 Initialize the NobleClient and allocate a relay. More...
 
new void StartClient ()
 Like NetworkManager.StartClient() but utilizes the Noble Connect relay and punchthrough services. More...
 
void StartClient (IPEndPoint hostEndPoint)
 Connect to a HostEndPoint, utilizing the Noble Connect relay and punchthrough services. More...
 
void StartClientLANOnly (IPEndPoint hostEndPoint)
 Start a client in LAN only mode. No relays or punchthrough will be used. More...
 
void StartClientLANOnly ()
 Start a client in LAN only mode. No relays or punchthrough will be used. More...
 
new void StopClient ()
 Stop the client. More...
 
override NetworkClient StartHost ()
 Start hosting, connect a local client, and request a HostEndPoint from the NobleConnectServices More...
 
NetworkClient StartHostLANOnly ()
 Start hosting, connect a local client, but do no create a relay or enable punchthrough More...
 
new void StartServer ()
 Start a server and request a HostEndPoint from the NobleConnectServices More...
 
void StartServerLANonly ()
 Start a server, but do no create a relay or enable punchthrough More...
 
override void OnStartClient (NetworkClient unetClient)
 
override void OnStartServer ()
 Called when hosting starts. More...
 
void OnStartServerLANOnly ()
 
IPAddress GetALANAddress ()
 
virtual void OnFatalError (string errorMessage)
 Override this method to be informed when something goes horribly wrong. More...
 
override void OnStopServer ()
 Cleans up the server More...
 
override void OnServerConnect (NetworkConnection conn)
 Called when the server receives a client connection. More...
 
override void OnClientDisconnect (NetworkConnection conn)
 
override void OnServerDisconnect (NetworkConnection conn)
 Called on the server when a client disconnects More...
 
virtual void OnServerPrepared (string hostAddress, ushort hostPort)
 Override this method to know when a Server has received their HostEndPoint More...
 

Public Attributes

new NobleClient client
 The NobleClient that will be used to connect to the host. More...
 
GeographicRegion region = GeographicRegion.AUTO
 The geographic region to use when selecting a relay server. More...
 
bool forceRelayConnection
 You can enable this to force relay connections to be used for testing purposes. More...
 
int relayRefreshTime = 30
 How often to send relay refresh requests, in seconds. More...
 
float relayRefreshTimeout = .1f
 Initial timeout before resending refresh messages. This is doubled for each failed resend. More...
 
int maxRelayRefreshAttempts = 3
 Max number of times to try and resend refresh messages before giving up and shutting down the relay connection. More...
 
int relayLifetime = 30
 How long a relay will stay alive without being refreshed (in seconds) More...
 

Protected Member Functions

virtual void OnDestroy ()
 Clean up the client and server. More...
 

Protected Attributes

bool isLANOnly
 If the current connection is LAN only More...
 

Properties

IPEndPoint HostEndPoint [get]
 This is the address that clients should connect to. It is assigned by the relay server. More...
 

Detailed Description

A NetworkManager that utilizes the Noble Connect relay and punchthrough services

This works almost exactly the same as the Unity NetworkManager. One difference though is that the host will not know the address that clients should connect to until it has been assigned by the Noble Connect servers. You can override the OnServerPrepared() method to know when this has happened and to get the hostAddress and hostPort (collectively known as the HostEndPoint) that clients should use to connect to the host. You can also get this address any time after it has been assigned via the server.HostEndPoint property.

Member Function Documentation

◆ Awake()

virtual void NobleConnect.UNet.NobleNetworkManager.Awake ( )
virtual

Initialize connectionConfig and HostTopology plus some other important setup.

If you override this method you must call the base method or everything will explode.

◆ GetALANAddress()

IPAddress NobleConnect.UNet.NobleNetworkManager.GetALANAddress ( )

◆ InitClient()

void NobleConnect.UNet.NobleNetworkManager.InitClient ( )

Initialize the NobleClient and allocate a relay.

You can call as soon as you know that the player intends to connect to host or even as soon as your game is launched. Initializing takes a few seconds, so doing it early can make connections seem quicker. If you do not call this method it will be called for you when you try and connect.

◆ OnClientDisconnect()

override void NobleConnect.UNet.NobleNetworkManager.OnClientDisconnect ( NetworkConnection  conn)

◆ OnDestroy()

virtual void NobleConnect.UNet.NobleNetworkManager.OnDestroy ( )
protectedvirtual

Clean up the client and server.

If you override this method you must call the base method or resources will not be properly cleaned up.

◆ OnFatalError()

virtual void NobleConnect.UNet.NobleNetworkManager.OnFatalError ( string  errorMessage)
virtual

Override this method to be informed when something goes horribly wrong.

You should see an error in your console with more info any time this is called. Generally it will either mean you've completely lost connection to the relay server or you have exceeded your CCU or bandwidth limit.

◆ OnServerConnect()

override void NobleConnect.UNet.NobleNetworkManager.OnServerConnect ( NetworkConnection  conn)

Called when the server receives a client connection.

If you override this method you must call the base method or everything will explode.

Parameters
connThe NetworkConnection of the connecting client


◆ OnServerDisconnect()

override void NobleConnect.UNet.NobleNetworkManager.OnServerDisconnect ( NetworkConnection  conn)

Called on the server when a client disconnects

If you override this method you must call the base method or resources will not be properly cleaned up.

Parameters
connThe NetworkConnection of the disconnecting client

◆ OnServerPrepared()

virtual void NobleConnect.UNet.NobleNetworkManager.OnServerPrepared ( string  hostAddress,
ushort  hostPort 
)
virtual

Override this method to know when a Server has received their HostEndPoint

If you are using some sort matchmaking this is a good time to create a match now that you have the HostEndPoint that clients will need to connect to.

Parameters
hostAddressThe address of the HostEndPoint the clients should use when connecting to the host.
hostPortThe port of the HostEndPoint that clients should use when connecting to the host

◆ OnStartClient()

override void NobleConnect.UNet.NobleNetworkManager.OnStartClient ( NetworkClient  unetClient)

◆ OnStartServer()

override void NobleConnect.UNet.NobleNetworkManager.OnStartServer ( )

Called when hosting starts.

If you override this method you must call the base method or everything will explode.

◆ OnStartServerLANOnly()

void NobleConnect.UNet.NobleNetworkManager.OnStartServerLANOnly ( )

◆ OnStopServer()

override void NobleConnect.UNet.NobleNetworkManager.OnStopServer ( )

Cleans up the server

If you override this method you must call the base method or resources will not be properly cleaned up.

◆ Start()

virtual void NobleConnect.UNet.NobleNetworkManager.Start ( )
virtual

◆ StartClient() [1/2]

new void NobleConnect.UNet.NobleNetworkManager.StartClient ( )

Like NetworkManager.StartClient() but utilizes the Noble Connect relay and punchthrough services.

Just like UNet's StartClient(), this method uses the NetworkManager's networkAddress and networkPort, so make sure to set those to the host's HostEndPoint before calling this method.

◆ StartClient() [2/2]

void NobleConnect.UNet.NobleNetworkManager.StartClient ( IPEndPoint  hostEndPoint)

Connect to a HostEndPoint, utilizing the Noble Connect relay and punchthrough services.

◆ StartClientLANOnly() [1/2]

void NobleConnect.UNet.NobleNetworkManager.StartClientLANOnly ( )

Start a client in LAN only mode. No relays or punchthrough will be used.

You will need the host's LAN ip to connect using this method. Just like UNet's StartClient(), this method uses the NetworkManager's networkAddress and networkPort, so make sure to set those to the host's LAN ip before calling this method.

◆ StartClientLANOnly() [2/2]

void NobleConnect.UNet.NobleNetworkManager.StartClientLANOnly ( IPEndPoint  hostEndPoint)

Start a client in LAN only mode. No relays or punchthrough will be used.

You will need the host's LAN ip to connect using this method.

Parameters
hostEndPoint

◆ StartHost()

override NetworkClient NobleConnect.UNet.NobleNetworkManager.StartHost ( )

Start hosting, connect a local client, and request a HostEndPoint from the NobleConnectServices

OnServerPrepared will be called when the HostEndPoint has been retrieved and the host is ready to receive relay / punchthrough connections.

◆ StartHostLANOnly()

NetworkClient NobleConnect.UNet.NobleNetworkManager.StartHostLANOnly ( )

Start hosting, connect a local client, but do no create a relay or enable punchthrough

Returns
OnServerPrepared will be called immediately and passed the local LAN address that clients can use to connect.

◆ StartServer()

new void NobleConnect.UNet.NobleNetworkManager.StartServer ( )

Start a server and request a HostEndPoint from the NobleConnectServices

OnServerPrepared will be called when the HostEndPoint has been retrieved and the host is ready to receive relay / punchthrough connections.

◆ StartServerLANonly()

void NobleConnect.UNet.NobleNetworkManager.StartServerLANonly ( )

Start a server, but do no create a relay or enable punchthrough

OnServerPrepared will be called immediately and passed the local LAN address that clients can use to connect.

◆ StopClient()

new void NobleConnect.UNet.NobleNetworkManager.StopClient ( )

Stop the client.

In most cases it is not recommended to call this method to disconnect the client as it will cause a timeout on the host. You should instead call client.connection.Disconenct() to send a disconnect message to the host and disconnect cleanly.

◆ Update()

virtual void NobleConnect.UNet.NobleNetworkManager.Update ( )
virtual

Updates the NobleClient and NobleServer.

If you override this method you must call the base method or everything will explode.

Member Data Documentation

◆ client

new NobleClient NobleConnect.UNet.NobleNetworkManager.client

The NobleClient that will be used to connect to the host.

◆ forceRelayConnection

bool NobleConnect.UNet.NobleNetworkManager.forceRelayConnection

You can enable this to force relay connections to be used for testing purposes.

Disables punchthrough and direct connections. Forces connections to use the relays. This is useful if you want to test your game with the unavoidable latency that is introduced when the relay servers are used. Note that you will tend to use more bandwidth on the relay servers while this is enabled than you typically would.

◆ isLANOnly

bool NobleConnect.UNet.NobleNetworkManager.isLANOnly
protected

If the current connection is LAN only

◆ maxRelayRefreshAttempts

int NobleConnect.UNet.NobleNetworkManager.maxRelayRefreshAttempts = 3

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.

◆ region

GeographicRegion NobleConnect.UNet.NobleNetworkManager.region = GeographicRegion.AUTO

The geographic region to use when selecting a relay server.

Defaults to AUTO which will automatically select the closest region. This is useful if you would like your players to be able to choose their region at run time. Note that players are not prevented from connecting across regions. That would need to be implementing separately via matchmaking for example, by filtering out matches from undesired regions.

◆ relayLifetime

int NobleConnect.UNet.NobleNetworkManager.relayLifetime = 30

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.UNet.NobleNetworkManager.relayRefreshTime = 30

How often to send relay refresh requests, in seconds.

◆ relayRefreshTimeout

float NobleConnect.UNet.NobleNetworkManager.relayRefreshTimeout = .1f

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

Property Documentation

◆ HostEndPoint

IPEndPoint NobleConnect.UNet.NobleNetworkManager.HostEndPoint
get

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.