Noble Connect
Add relays, punchthrough, and automatic port-forwarding to any networking system.
NobleClient Class Reference

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

Public Member Functions

 NobleClient (HostTopology topo=null, Action onFatalError=null)
 Initialize the client using NobleConnectSettings. The region used is determined by the Relay Server Address in the NobleConnectSettings. More...
 
 NobleClient (string relayServerAddress, HostTopology topo=null, Action onFatalError=null)
 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 Update ()
 If you are using the NetworkClient directly you must call this method every frame. More...
 
void Connect (string hostIP, ushort hostPort)
 Connect to the provided host ip and port More...
 
void Connect (IPEndPoint hostEndPoint)
 Connect to the provided HostEndPoint More...
 
void Shutdown ()
 Shut down the client and clean everything up. More...
 

Public Attributes

NetworkClient unetClient
 The NetworkClient that will connect over the bridge to the relay More...
 
ConnectionType latestConnectionType = ConnectionType.NONE
 You can check this in OnClientConnect(), it will either be Direct, Punchthrough, or Relay. More...
 
bool isConnecting = false
 A convenient way to check if a connection is in progress More...
 

Protected Member Functions

override void Dispose (bool disposing)
 Clean up and free resources. Called automatically when garbage collected. More...
 

Properties

bool ForceRelayOnly [get, set]
 You can use this to force the relays to be used for testing purposes. More...
 

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/2]

NobleClient ( HostTopology  topo = null,
Action  onFatalError = null 
)
inline

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.

◆ NobleClient() [2/2]

NobleClient ( string  relayServerAddress,
HostTopology  topo = null,
Action  onFatalError = null 
)
inline

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.

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.
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.

Member Function Documentation

◆ Connect() [1/2]

void Connect ( string  hostIP,
ushort  hostPort 
)
inline

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
topoThe HostTopology to use for the NetworkServer.

◆ Connect() [2/2]

void Connect ( IPEndPoint  hostEndPoint)
inline

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
hostPortThe port of the server's HostEndPoint
topoThe HostTopology to use for the NetworkServer.

◆ Dispose()

override void Dispose ( bool  disposing)
inlineprotected

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

◆ Shutdown()

void Shutdown ( )
inline

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.

◆ Update()

void Update ( )
inline

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

◆ isConnecting

bool isConnecting = false

A convenient way to check if a connection is in progress

◆ latestConnectionType

ConnectionType latestConnectionType = ConnectionType.NONE

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

◆ unetClient

NetworkClient unetClient

The NetworkClient that will connect over the bridge to the relay

Property Documentation

◆ ForceRelayOnly

bool ForceRelayOnly
getset

You can use this to force the relays to be used for testing purposes.