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

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

Public Member Functions

 NobleServer (HostTopology topo=null, Action< string, ushort > onPrepared=null, Action onFatalError=null)
 Initialize the server using NobleConnectSettings. The region used is determined by the Relay Server Address in the NobleConnectSettings. More...
 
 NobleServer (string relayServerAddress, HostTopology topo=null, Action< string, ushort > onPrepared=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...
 
virtual void Update ()
 If you are using the NetworkServer directly you must call this method every frame. More...
 
void Listen (ushort unetServerPort=0, Action< string, ushort > onReady=null)
 Start listening for incoming connections More...
 
void RegisterHandler (short msgType, NetworkMessageDelegate handler)
 Register a handler for a particular message type. 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...
 
IPEndPoint HostEndPoint [get]
 This is the address that clients should connect to. It is assigned by the relay server. More...
 

Detailed Description

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

Use the Listen method to start listening for incoming connections.

Constructor & Destructor Documentation

◆ NobleServer() [1/2]

NobleServer ( HostTopology  topo = null,
Action< string, ushort >  onPrepared = null,
Action  onFatalError = null 
)
inline

Initialize the server 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.
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.

◆ NobleServer() [2/2]

NobleServer ( string  relayServerAddress,
HostTopology  topo = null,
Action< string, ushort >  onPrepared = 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.
onPreparedA method to call when the host has received their HostEndPoint from the relay server.
onFatalErrorA method to call if something goes horribly wrong.

Member Function Documentation

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

Parameters
disposing

◆ Listen()

void Listen ( ushort  unetServerPort = 0,
Action< string, ushort >  onReady = null 
)
inline

Start listening for incoming connections

Don't forget you will still need to call AddPeer() for each peer that you want to allow to connect via relay.

Parameters
unetServerPort

◆ RegisterHandler()

void RegisterHandler ( short  msgType,
NetworkMessageDelegate  handler 
)
inline

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.

◆ Update()

virtual void Update ( )
inlinevirtual

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.

Property Documentation

◆ ForceRelayOnly

bool ForceRelayOnly
getset

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

◆ HostEndPoint

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