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

Adds relay and punchthrough support to the Unity NetworkServer More...

Static Public Member Functions

static void InitializeHosting (int listenPort, GeographicRegion region=GeographicRegion.AUTO, HostTopology topo=null, 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, HostTopology topo=null, 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 _Init (int listenPort, string relayServerAddress, HostTopology topo=null, Action< string, ushort > onPrepared=null, Action< string > onFatalError=null, bool forceRelayOnly=false)
 Initialize the NetworkServer and Ice.Controller 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, HostTopology topo=null, Action< string, ushort > onPrepared=null, Action< string > onFatalError=null, bool forceRelayOnly=false)
 Start listening for incoming connections More...
 
static void RegisterHandler (short msgType, NetworkMessageDelegate handler)
 Register a handler for a particular message type. More...
 
static void UnregisterHandler (short msgType)
 
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)
 
static void SetNetworkConnectionClass< T > ()
 
static bool Configure (ConnectionConfig config, int maxConnections)
 
static bool Configure (HostTopology topology)
 
static void Reset ()
 
static void Shutdown ()
 
static NetworkClient BecomeHost (NetworkClient oldClient, int port, MatchInfo matchInfo, int oldConnectionId, PeerInfoMessage[] peers)
 
static bool SendToAll (short msgType, MessageBase msg)
 
static bool SendToReady (GameObject contextObj, short msgType, MessageBase msg)
 
static void SendWriterToReady (GameObject contextObj, NetworkWriter writer, int channelId)
 
static void SendBytesToReady (GameObject contextObj, byte[] buffer, int numBytes, int channelId)
 
static void SendBytesToPlayer (GameObject player, byte[] buffer, int numBytes, int channelId)
 
static bool SendUnreliableToAll (short msgType, MessageBase msg)
 
static bool SendUnreliableToReady (GameObject contextObj, short msgType, MessageBase msg)
 
static bool SendByChannelToAll (short msgType, MessageBase msg, int channelId)
 
static bool SendByChannelToReady (GameObject contextObj, short msgType, MessageBase msg, int channelId)
 
static void DisconnectAll ()
 
static void ClearSpawners ()
 
static void GetStatsOut (out int numMsgs, out int numBufferedMsgs, out int numBytes, out int lastBufferedPerSecond)
 
static void GetStatsIn (out int numMsgs, out int numBytes)
 
static void SendToClientOfPlayer (GameObject player, short msgType, MessageBase msg)
 
static void SendToClient (int connectionId, short msgType, MessageBase msg)
 
static bool ReplacePlayerForConnection (NetworkConnection conn, GameObject player, short playerControllerId, NetworkHash128 assetId)
 
static bool ReplacePlayerForConnection (NetworkConnection conn, GameObject player, short playerControllerId)
 
static bool AddPlayerForConnection (NetworkConnection conn, GameObject player, short playerControllerId, NetworkHash128 assetId)
 
static bool AddPlayerForConnection (NetworkConnection conn, GameObject player, short playerControllerId)
 
static void SetClientReady (NetworkConnection conn)
 
static void SetAllClientsNotReady ()
 
static void SetClientNotReady (NetworkConnection conn)
 
static void DestroyPlayersForConnection (NetworkConnection conn)
 
static void ClearLocalObjects ()
 
static void Spawn (GameObject obj)
 
static bool SpawnWithClientAuthority (GameObject obj, GameObject player)
 
static bool SpawnWithClientAuthority (GameObject obj, NetworkConnection conn)
 
static bool SpawnWithClientAuthority (GameObject obj, NetworkHash128 assetId, NetworkConnection conn)
 
static void Spawn (GameObject obj, NetworkHash128 assetId)
 
static void Destroy (GameObject obj)
 
static void UnSpawn (GameObject obj)
 
static GameObject FindLocalObject (NetworkInstanceId netId)
 
static Dictionary< short, NetworkConnection.PacketStat > GetConnectionStats ()
 
static void ResetConnectionStats ()
 
static bool AddExternalConnection (NetworkConnection conn)
 
static void RemoveExternalConnection (int connectionId)
 
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 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 List< NetworkConnection > localConnections [get]
 
static int listenPort [get]
 
static int serverHostId [get]
 
static ReadOnlyCollection< NetworkConnection > connections [get]
 
static Dictionary< short, NetworkMessageDelegate > handlers [get]
 
static HostTopology hostTopology [get]
 
static Dictionary< NetworkInstanceId, NetworkIdentity > objects [get]
 
static bool dontListen [get, set]
 
static bool useWebSockets [get, set]
 
static bool active [get]
 
static bool localClientActive [get]
 
static int numChannels [get]
 
static float maxDelay [get, set]
 
static Type networkConnectionClass [get]
 

Detailed Description

Adds relay and punchthrough support to the Unity NetworkServer

Use the Listen method to start listening for incoming connections.

Member Function Documentation

◆ _Init()

static void NobleConnect.UNet.NobleServer._Init ( int  listenPort,
string  relayServerAddress,
HostTopology  topo = null,
Action< string, ushort >  onPrepared = null,
Action< string >  onFatalError = null,
bool  forceRelayOnly = false 
)
static

Initialize the NetworkServer and Ice.Controller

◆ AddExternalConnection()

static bool NobleConnect.UNet.NobleServer.AddExternalConnection ( NetworkConnection  conn)
static

◆ AddPlayerForConnection() [1/2]

static bool NobleConnect.UNet.NobleServer.AddPlayerForConnection ( NetworkConnection  conn,
GameObject  player,
short  playerControllerId 
)
static

◆ AddPlayerForConnection() [2/2]

static bool NobleConnect.UNet.NobleServer.AddPlayerForConnection ( NetworkConnection  conn,
GameObject  player,
short  playerControllerId,
NetworkHash128  assetId 
)
static

◆ BecomeHost()

static NetworkClient NobleConnect.UNet.NobleServer.BecomeHost ( NetworkClient  oldClient,
int  port,
MatchInfo  matchInfo,
int  oldConnectionId,
PeerInfoMessage[]  peers 
)
static

◆ ClearHandlers()

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

◆ ClearLocalObjects()

static void NobleConnect.UNet.NobleServer.ClearLocalObjects ( )
static

◆ ClearSpawners()

static void NobleConnect.UNet.NobleServer.ClearSpawners ( )
static

◆ Configure() [1/2]

static bool NobleConnect.UNet.NobleServer.Configure ( ConnectionConfig  config,
int  maxConnections 
)
static

◆ Configure() [2/2]

static bool NobleConnect.UNet.NobleServer.Configure ( HostTopology  topology)
static

◆ Destroy()

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

◆ DestroyPlayersForConnection()

static void NobleConnect.UNet.NobleServer.DestroyPlayersForConnection ( NetworkConnection  conn)
static

◆ DisconnectAll()

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

◆ Dispose()

static void NobleConnect.UNet.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 GameObject NobleConnect.UNet.NobleServer.FindLocalObject ( NetworkInstanceId  netId)
static

◆ GetConnectionStats()

static Dictionary<short, NetworkConnection.PacketStat> NobleConnect.UNet.NobleServer.GetConnectionStats ( )
static

◆ GetStatsIn()

static void NobleConnect.UNet.NobleServer.GetStatsIn ( out int  numMsgs,
out int  numBytes 
)
static

◆ GetStatsOut()

static void NobleConnect.UNet.NobleServer.GetStatsOut ( out int  numMsgs,
out int  numBufferedMsgs,
out int  numBytes,
out int  lastBufferedPerSecond 
)
static

◆ InitializeHosting() [1/2]

static void NobleConnect.UNet.NobleServer.InitializeHosting ( int  listenPort,
GeographicRegion  region = GeographicRegion.AUTO,
HostTopology  topo = null,
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.UNet.NobleServer.InitializeHosting ( int  listenPort,
string  relayServerAddress,
HostTopology  topo = null,
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.UNet.NobleServer.Listen ( int  port = 0,
GeographicRegion  region = GeographicRegion.AUTO,
HostTopology  topo = null,
Action< string, ushort >  onPrepared = null,
Action< string >  onFatalError = null,
bool  forceRelayOnly = false 
)
static

Start listening for incoming connections

Parameters
port
onPreparedA method to call when the host has received their HostEndPoint from the relay server.

◆ OnServerConnect()

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

◆ OnServerDisconnect()

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

◆ RegisterHandler()

static void NobleConnect.UNet.NobleServer.RegisterHandler ( short  msgType,
NetworkMessageDelegate  handler 
)
static

Register a handler for a particular message type.

There are several system message types which you can add handlers for. You can also add your own message types.

Parameters
msgTypeMessage type number.
handlerFunction handler which will be invoked for when this message type is received.

◆ RemoveExternalConnection()

static void NobleConnect.UNet.NobleServer.RemoveExternalConnection ( int  connectionId)
static

◆ ReplacePlayerForConnection() [1/2]

static bool NobleConnect.UNet.NobleServer.ReplacePlayerForConnection ( NetworkConnection  conn,
GameObject  player,
short  playerControllerId 
)
static

◆ ReplacePlayerForConnection() [2/2]

static bool NobleConnect.UNet.NobleServer.ReplacePlayerForConnection ( NetworkConnection  conn,
GameObject  player,
short  playerControllerId,
NetworkHash128  assetId 
)
static

◆ Reset()

static void NobleConnect.UNet.NobleServer.Reset ( )
static

◆ ResetConnectionStats()

static void NobleConnect.UNet.NobleServer.ResetConnectionStats ( )
static

◆ SendByChannelToAll()

static bool NobleConnect.UNet.NobleServer.SendByChannelToAll ( short  msgType,
MessageBase  msg,
int  channelId 
)
static

◆ SendByChannelToReady()

static bool NobleConnect.UNet.NobleServer.SendByChannelToReady ( GameObject  contextObj,
short  msgType,
MessageBase  msg,
int  channelId 
)
static

◆ SendBytesToPlayer()

static void NobleConnect.UNet.NobleServer.SendBytesToPlayer ( GameObject  player,
byte[]  buffer,
int  numBytes,
int  channelId 
)
static

◆ SendBytesToReady()

static void NobleConnect.UNet.NobleServer.SendBytesToReady ( GameObject  contextObj,
byte[]  buffer,
int  numBytes,
int  channelId 
)
static

◆ SendToAll()

static bool NobleConnect.UNet.NobleServer.SendToAll ( short  msgType,
MessageBase  msg 
)
static

◆ SendToClient()

static void NobleConnect.UNet.NobleServer.SendToClient ( int  connectionId,
short  msgType,
MessageBase  msg 
)
static

◆ SendToClientOfPlayer()

static void NobleConnect.UNet.NobleServer.SendToClientOfPlayer ( GameObject  player,
short  msgType,
MessageBase  msg 
)
static

◆ SendToReady()

static bool NobleConnect.UNet.NobleServer.SendToReady ( GameObject  contextObj,
short  msgType,
MessageBase  msg 
)
static

◆ SendUnreliableToAll()

static bool NobleConnect.UNet.NobleServer.SendUnreliableToAll ( short  msgType,
MessageBase  msg 
)
static

◆ SendUnreliableToReady()

static bool NobleConnect.UNet.NobleServer.SendUnreliableToReady ( GameObject  contextObj,
short  msgType,
MessageBase  msg 
)
static

◆ SendWriterToReady()

static void NobleConnect.UNet.NobleServer.SendWriterToReady ( GameObject  contextObj,
NetworkWriter  writer,
int  channelId 
)
static

◆ SetAllClientsNotReady()

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

◆ SetClientNotReady()

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

◆ SetClientReady()

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

◆ SetNetworkConnectionClass< T >()

static void NobleConnect.UNet.NobleServer.SetNetworkConnectionClass< T > ( )
static
Type Constraints
T :NetworkConnection 

◆ Shutdown()

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

◆ Spawn() [1/2]

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

◆ Spawn() [2/2]

static void NobleConnect.UNet.NobleServer.Spawn ( GameObject  obj,
NetworkHash128  assetId 
)
static

◆ SpawnObjects()

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

◆ SpawnWithClientAuthority() [1/3]

static bool NobleConnect.UNet.NobleServer.SpawnWithClientAuthority ( GameObject  obj,
GameObject  player 
)
static

◆ SpawnWithClientAuthority() [2/3]

static bool NobleConnect.UNet.NobleServer.SpawnWithClientAuthority ( GameObject  obj,
NetworkConnection  conn 
)
static

◆ SpawnWithClientAuthority() [3/3]

static bool NobleConnect.UNet.NobleServer.SpawnWithClientAuthority ( GameObject  obj,
NetworkHash128  assetId,
NetworkConnection  conn 
)
static

◆ UnregisterHandler()

static void NobleConnect.UNet.NobleServer.UnregisterHandler ( short  msgType)
static

◆ UnSpawn()

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

◆ Update()

static void NobleConnect.UNet.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.UNet.NobleServer.allocationResendTimeout = .1f
static

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

◆ maxAllocationResends

int NobleConnect.UNet.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.UNet.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.UNet.NobleServer.relayRefreshTime = 30
static

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

Property Documentation

◆ active

bool NobleConnect.UNet.NobleServer.active
staticget

◆ connections

ReadOnlyCollection<NetworkConnection> NobleConnect.UNet.NobleServer.connections
staticget

◆ dontListen

bool NobleConnect.UNet.NobleServer.dontListen
staticgetset

◆ handlers

Dictionary<short, NetworkMessageDelegate> NobleConnect.UNet.NobleServer.handlers
staticget

◆ HostEndPoint

IPEndPoint NobleConnect.UNet.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.

◆ hostTopology

HostTopology NobleConnect.UNet.NobleServer.hostTopology
staticget

◆ listenPort

int NobleConnect.UNet.NobleServer.listenPort
staticget

◆ localClientActive

bool NobleConnect.UNet.NobleServer.localClientActive
staticget

◆ localConnections

List<NetworkConnection> NobleConnect.UNet.NobleServer.localConnections
staticget

◆ maxDelay

float NobleConnect.UNet.NobleServer.maxDelay
staticgetset

◆ networkConnectionClass

Type NobleConnect.UNet.NobleServer.networkConnectionClass
staticget

◆ numChannels

int NobleConnect.UNet.NobleServer.numChannels
staticget

◆ objects

Dictionary<NetworkInstanceId, NetworkIdentity> NobleConnect.UNet.NobleServer.objects
staticget

◆ serverHostId

int NobleConnect.UNet.NobleServer.serverHostId
staticget

◆ useWebSockets

bool NobleConnect.UNet.NobleServer.useWebSockets
staticgetset