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

Adds relay, punchthrough, and port-forwarding support to the Unity NetworkClient More...

Public Member Functions

 NobleClient (GeographicRegion region=GeographicRegion.AUTO, HostTopology topo=null, Action< string > onFatalError=null, int relayLifetime=60, int relayRefreshTime=30, float allocationResendTimeout=.1f, int maxAllocationResends=8)
 Initialize the client using NobleConnectSettings. The region used is determined by the Relay Server Address in the NobleConnectSettings. More...
 
 NobleClient (HostTopology topo=null)
 Create a LAN only client More...
 
 NobleClient (NetworkClient unetClient)
 Create a NobleClient using an existing NetworkClient More...
 
 NobleClient (string relayServerAddress, HostTopology topo=null, Action< string > onFatalError=null, int relayLifetime=60, int relayRefreshTime=30, float allocationResendTimeout=.1f, int maxAllocationResends=8)
 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...
 
void PrepareToConnect ()
 Prepare to connect but don't actually connect yet More...
 
void Update ()
 If you are using the NetworkClient directly you must call this method every frame. More...
 
void Connect (string hostIP, ushort hostPort, bool isLANOnly=false)
 Connect to the provided host ip and port More...
 
void Connect (IPEndPoint hostEndPoint, bool isLANOnly=false)
 Connect to the provided HostEndPoint More...
 
void Shutdown ()
 Shut down the client and clean everything up. More...
 
void Dispose (bool disposing)
 Clean up and free resources. Called automatically when garbage collected. More...
 
void Dispose ()
 
void SetNetworkConnectionClass< T > ()
 
bool Configure (ConnectionConfig config, int maxConnections)
 
bool Configure (HostTopology topology)
 
bool ReconnectToNewHost (string serverIp, int serverPort)
 
bool ReconnectToNewHost (EndPoint secureTunnelEndPoint)
 
void ConnectWithSimulator (string serverIp, int serverPort, int latency, float packetLoss)
 
bool Send (short msgType, MessageBase msg)
 
bool SendWriter (NetworkWriter writer, int channelId)
 
bool SendBytes (byte[] data, int numBytes, int channelId)
 
bool SendUnreliable (short msgType, MessageBase msg)
 
bool SendByChannel (short msgType, MessageBase msg, int channelId)
 
void SetMaxDelay (float seconds)
 
void GetStatsOut (out int numMsgs, out int numBufferedMsgs, out int numBytes, out int lastBufferedPerSecond)
 
void GetStatsIn (out int numMsgs, out int numBytes)
 
Dictionary< short, NetworkConnection.PacketStat > GetConnectionStats ()
 
void ResetConnectionStats ()
 
int GetRTT ()
 
void RegisterHandler (short msgType, NetworkMessageDelegate handler)
 
void RegisterHandlerSafe (short msgType, NetworkMessageDelegate handler)
 
void UnregisterHandler (short msgType)
 

Public Attributes

NetworkClient unetClient
 The NetworkClient that will connect over the bridge to the relay More...
 
bool isConnecting = false
 A convenient way to check if a connection is in progress More...
 
bool ForceRelayOnly
 Store force relay so that we can pass it on to the iceController More...
 

Properties

ConnectionType latestConnectionType [get, set]
 You can check this in OnClientConnect(), it will either be Direct, Punchthrough, or Relay. More...
 
static bool active [get]
 
string serverIp [get]
 The rest of this is just a wrapper for UNET's NetworkClient. More...
 
int serverPort [get]
 
NetworkConnection connection [get]
 
Dictionary< short, NetworkMessageDelegate > handlers [get]
 
int numChannels [get]
 
HostTopology hostTopology [get]
 
bool? isConnected [get]
 
Type networkConnectionClass [get]
 

Detailed Description

Adds relay, punchthrough, and port-forwarding support to the Unity NetworkClient

Use the Connect method to connect to a host.

Constructor & Destructor Documentation

◆ NobleClient() [1/4]

NobleConnect.UNet.NobleClient.NobleClient ( GeographicRegion  region = GeographicRegion.AUTO,
HostTopology  topo = null,
Action< string >  onFatalError = null,
int  relayLifetime = 60,
int  relayRefreshTime = 30,
float  allocationResendTimeout = .1f,
int  maxAllocationResends = 8 
)

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

The default address is connect.noblewhale.com, which will automatically select the closest server based on geographic region.

If you would like to connect to a specific region you can use one of the following urls:

    us-east.connect.noblewhale.com - Eastern United States
    us-west.connect.noblewhale.com - Western United States
    eu.connect.noblewhale.com - Europe
    ap.connect.noblewhale.com - Asia-Pacific
    sa.connect.noblewhale.com - South Africa

Note that region selection will ensure each player connects to the closest relay server, but it does not prevent players from connecting across regions. If you want to prevent joining across regions you will need to implement that separately (by filtering out unwanted regions during matchmaking for example).

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.
allocationResendTimeoutInitial timeout before resending refresh messages. This is doubled for each failed resend.
maxAllocationResendsMax 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.

◆ NobleClient() [2/4]

NobleConnect.UNet.NobleClient.NobleClient ( HostTopology  topo = null)

Create a LAN only client

Clients created in this way will have no relay or punchthrough capabilities.

◆ NobleClient() [3/4]

NobleConnect.UNet.NobleClient.NobleClient ( NetworkClient  unetClient)

Create a NobleClient using an existing NetworkClient

This is used for the local client on hosts.

◆ NobleClient() [4/4]

NobleConnect.UNet.NobleClient.NobleClient ( string  relayServerAddress,
HostTopology  topo = null,
Action< string >  onFatalError = null,
int  relayLifetime = 60,
int  relayRefreshTime = 30,
float  allocationResendTimeout = .1f,
int  maxAllocationResends = 8 
)

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.
onFatalErrorA method to call if something goes horribly wrong.
allocationResendTimeoutInitial timeout before resending refresh messages. This is doubled for each failed resend.
maxAllocationResendsMax 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.

Member Function Documentation

◆ Configure() [1/2]

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

◆ Configure() [2/2]

bool NobleConnect.UNet.NobleClient.Configure ( HostTopology  topology)

◆ Connect() [1/2]

void NobleConnect.UNet.NobleClient.Connect ( IPEndPoint  hostEndPoint,
bool  isLANOnly = false 
)

Connect to the provided HostEndPoint

Note that the host address used here should be the one provided to the host by the relay server, not the actual ip of the host's computer. You can get this address on the host from Server.HostEndPoint.

Parameters
hostEndPointThe HostEndPoint of the server to connect to
isLANOnlyConnect to LAN host address instead of using relays / punchthrough

◆ Connect() [2/2]

void NobleConnect.UNet.NobleClient.Connect ( string  hostIP,
ushort  hostPort,
bool  isLANOnly = false 
)

Connect to the provided host ip and port

Note that the host address used here should be the one provided to the host by the relay server, not the actual ip of the host's computer. You can get this address on the host from Server.HostEndPoint.

Parameters
hostIPThe IP of the server's HostEndPoint
hostPortThe port of the server's HostEndPoint
isLANOnlyConnect to LAN host address instead of using relays / punchthrough

◆ ConnectWithSimulator()

void NobleConnect.UNet.NobleClient.ConnectWithSimulator ( string  serverIp,
int  serverPort,
int  latency,
float  packetLoss 
)

◆ Dispose() [1/2]

void NobleConnect.UNet.NobleClient.Dispose ( )

◆ Dispose() [2/2]

void NobleConnect.UNet.NobleClient.Dispose ( bool  disposing)

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 NobleClient is garbage collected or when shutting down the application.

Parameters
disposing

◆ GetConnectionStats()

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

◆ GetRTT()

int NobleConnect.UNet.NobleClient.GetRTT ( )

◆ GetStatsIn()

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

◆ GetStatsOut()

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

◆ PrepareToConnect()

void NobleConnect.UNet.NobleClient.PrepareToConnect ( )

Prepare to connect but don't actually connect yet

This is used when initializing a client early before connecting. Getting this out of the way earlier can make the actual connection seem quicker.

◆ ReconnectToNewHost() [1/2]

bool NobleConnect.UNet.NobleClient.ReconnectToNewHost ( EndPoint  secureTunnelEndPoint)

◆ ReconnectToNewHost() [2/2]

bool NobleConnect.UNet.NobleClient.ReconnectToNewHost ( string  serverIp,
int  serverPort 
)

◆ RegisterHandler()

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

◆ RegisterHandlerSafe()

void NobleConnect.UNet.NobleClient.RegisterHandlerSafe ( short  msgType,
NetworkMessageDelegate  handler 
)

◆ ResetConnectionStats()

void NobleConnect.UNet.NobleClient.ResetConnectionStats ( )

◆ Send()

bool NobleConnect.UNet.NobleClient.Send ( short  msgType,
MessageBase  msg 
)

◆ SendByChannel()

bool NobleConnect.UNet.NobleClient.SendByChannel ( short  msgType,
MessageBase  msg,
int  channelId 
)

◆ SendBytes()

bool NobleConnect.UNet.NobleClient.SendBytes ( byte[]  data,
int  numBytes,
int  channelId 
)

◆ SendUnreliable()

bool NobleConnect.UNet.NobleClient.SendUnreliable ( short  msgType,
MessageBase  msg 
)

◆ SendWriter()

bool NobleConnect.UNet.NobleClient.SendWriter ( NetworkWriter  writer,
int  channelId 
)

◆ SetMaxDelay()

void NobleConnect.UNet.NobleClient.SetMaxDelay ( float  seconds)

◆ SetNetworkConnectionClass< T >()

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

◆ Shutdown()

void NobleConnect.UNet.NobleClient.Shutdown ( )

Shut down the client and clean everything up.

You can call this method if you are totally done with a client and don't plan on using it to connect again.

◆ UnregisterHandler()

void NobleConnect.UNet.NobleClient.UnregisterHandler ( short  msgType)

◆ Update()

void NobleConnect.UNet.NobleClient.Update ( )

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

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

Member Data Documentation

◆ ForceRelayOnly

bool NobleConnect.UNet.NobleClient.ForceRelayOnly

Store force relay so that we can pass it on to the iceController

◆ isConnecting

bool NobleConnect.UNet.NobleClient.isConnecting = false

A convenient way to check if a connection is in progress

◆ unetClient

NetworkClient NobleConnect.UNet.NobleClient.unetClient

The NetworkClient that will connect over the bridge to the relay

Property Documentation

◆ active

bool NobleConnect.UNet.NobleClient.active
staticget

◆ connection

NetworkConnection NobleConnect.UNet.NobleClient.connection
get

◆ handlers

Dictionary<short, NetworkMessageDelegate> NobleConnect.UNet.NobleClient.handlers
get

◆ hostTopology

HostTopology NobleConnect.UNet.NobleClient.hostTopology
get

◆ isConnected

bool? NobleConnect.UNet.NobleClient.isConnected
get

◆ latestConnectionType

ConnectionType NobleConnect.UNet.NobleClient.latestConnectionType
getset

You can check this in OnClientConnect(), it will either be Direct, Punchthrough, or Relay.

◆ networkConnectionClass

Type NobleConnect.UNet.NobleClient.networkConnectionClass
get

◆ numChannels

int NobleConnect.UNet.NobleClient.numChannels
get

◆ serverIp

string NobleConnect.UNet.NobleClient.serverIp
get

The rest of this is just a wrapper for UNET's NetworkClient.

◆ serverPort

int NobleConnect.UNet.NobleClient.serverPort
get