Adds relay, punchthrough, and port-forwarding support to the Mirror NetworkClient More...
Public Member Functions | |
NobleClient (GeographicRegion region=GeographicRegion.AUTO, Action< string > onFatalError=null, int relayLifetime=60, int relayRefreshTime=30, float allocationResendTimeout=.1f, int maxAllocationResends=8, float requestTimeout=.2f) | |
Initialize the client using NobleConnectSettings. The region used is determined by the Relay Server Address in the NobleConnectSettings. More... | |
NobleClient () | |
NobleClient (string relayServerAddress, Action< string > onFatalError=null, int relayLifetime=60, int relayRefreshTime=30, float allocationResendTimeout=.1f, int maxAllocationResends=8, float requestTimeout=.2f) | |
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 | SetConnectPort (ushort port) |
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 () |
bool | InvokeHandler< T > (T msg, int channelId) |
This function invokes the registered handler function for a message. More... | |
virtual void | OnClientConnect (NetworkConnection conn) |
Called on the client upon succesfully connecting to a host More... | |
virtual void | OnClientDisconnect (NetworkConnection conn) |
Called on the client upon disconnecting from a host More... | |
void | Connect (string address) |
Connect client to a NetworkServer instance. More... | |
void | Connect (Uri uri) |
Connect client to a NetworkServer instance. More... | |
void | ConnectHost () |
void | ConnectLocalServer () |
connect host mode More... | |
void | DisconnectLocalServer () |
disconnect host mode. this is needed to call DisconnectMessage for the host client too. More... | |
void | Disconnect () |
Disconnect from server. More... | |
void | Send< T > (T message, int channelId=Channels.DefaultReliable) |
This sends a network message with a message Id to the server. This message is sent on channel zero, which by default is the reliable channel. More... | |
void | RegisterHandler< T > (Action< NetworkConnection, T > handler, bool requireAuthentication=true) |
Register a handler for a particular message type. More... | |
void | RegisterHandler< T > (Action< T > handler, bool requireAuthentication=true) |
Register a handler for a particular message type. More... | |
void | ReplaceHandler< T > (Action< NetworkConnection, T > handler, bool requireAuthentication=true) |
Replaces a handler for a particular message type. More... | |
void | ReplaceHandler< T > (Action< T > handler, bool requireAuthentication=true) |
Replaces a handler for a particular message type. More... | |
bool | UnregisterHandler< T > () |
Unregisters a network message handler. More... | |
Public Attributes | |
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... | |
NetworkConnection | connection => NetworkClient.connection |
The rest of this is just a wrapper for Mirror's NetworkClient. More... | |
bool | active => NetworkClient.active |
active is true while a client is connecting/connected (= while the network is active) More... | |
bool | isConnected => NetworkClient.isConnected |
This gives the current connection status of the client. More... | |
bool | isLocalClient => NetworkClient.isLocalClient |
NetworkClient can connect to local server in host mode too More... | |
Properties | |
ConnectionType | latestConnectionType [get, set] |
You can check this in OnClientConnect(), it will either be Direct, Punchthrough, or Relay. More... | |
Adds relay, punchthrough, and port-forwarding support to the Mirror NetworkClient
Use the Connect method to connect to a host.
NobleConnect.Mirror.NobleClient.NobleClient | ( | GeographicRegion | region = GeographicRegion.AUTO , |
Action< string > | onFatalError = null , |
||
int | relayLifetime = 60 , |
||
int | relayRefreshTime = 30 , |
||
float | allocationResendTimeout = .1f , |
||
int | maxAllocationResends = 8 , |
||
float | requestTimeout = .2f |
||
) |
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 hk.connect.noblewhale.com - Hong Kong
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).
topo | The HostTopology to use for the NetworkClient. Must be the same on host and client. |
onFatalError | A method to call if something goes horribly wrong. |
allocationResendTimeout | Initial timeout before resending refresh messages. This is doubled for each failed resend. |
maxAllocationResends | 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. |
NobleConnect.Mirror.NobleClient.NobleClient | ( | ) |
NobleConnect.Mirror.NobleClient.NobleClient | ( | string | relayServerAddress, |
Action< string > | onFatalError = null , |
||
int | relayLifetime = 60 , |
||
int | relayRefreshTime = 30 , |
||
float | allocationResendTimeout = .1f , |
||
int | maxAllocationResends = 8 , |
||
float | requestTimeout = .2f |
||
) |
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.
relayServerAddress | The url or ip of the relay server to connect to |
topo | The HostTopology to use for the NetworkClient. Must be the same on host and client. |
onFatalError | A method to call if something goes horribly wrong. |
allocationResendTimeout | Initial timeout before resending refresh messages. This is doubled for each failed resend. |
maxAllocationResends | 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. |
void NobleConnect.Mirror.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.
hostEndPoint | The HostEndPoint of the server to connect to |
hostPort | The port of the server's HostEndPoint |
topo | The HostTopology to use for the NetworkServer. |
void NobleConnect.Mirror.NobleClient.Connect | ( | string | address | ) |
Connect client to a NetworkServer instance.
address |
void NobleConnect.Mirror.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.
hostIP | The IP of the server's HostEndPoint |
hostPort | The port of the server's HostEndPoint |
topo | The HostTopology to use for the NetworkServer. |
void NobleConnect.Mirror.NobleClient.Connect | ( | Uri | uri | ) |
Connect client to a NetworkServer instance.
uri | Address of the server to connect to |
void NobleConnect.Mirror.NobleClient.ConnectHost | ( | ) |
void NobleConnect.Mirror.NobleClient.ConnectLocalServer | ( | ) |
connect host mode
void NobleConnect.Mirror.NobleClient.Disconnect | ( | ) |
Disconnect from server.
The disconnect message will be invoked.
void NobleConnect.Mirror.NobleClient.DisconnectLocalServer | ( | ) |
disconnect host mode. this is needed to call DisconnectMessage for the host client too.
void NobleConnect.Mirror.NobleClient.Dispose | ( | ) |
void NobleConnect.Mirror.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.
disposing |
bool NobleConnect.Mirror.NobleClient.InvokeHandler< T > | ( | T | msg, |
int | channelId | ||
) |
This function invokes the registered handler function for a message.
Network connections used by the NetworkClient and NetworkServer use this function for handling network messages.
T | The message type to unregister. |
msg | The message object to process. |
T | : | struct | |
T | : | NetworkMessage |
|
virtual |
Called on the client upon succesfully connecting to a host
We clean some ice stuff up here.
message |
|
virtual |
Called on the client upon disconnecting from a host
Some memory and ports are freed here.
message |
void NobleConnect.Mirror.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.
void NobleConnect.Mirror.NobleClient.RegisterHandler< T > | ( | Action< NetworkConnection, T > | handler, |
bool | requireAuthentication = true |
||
) |
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.
T | Message type |
handler | Function handler which will be invoked when this message type is received. |
requireAuthentication | True if the message requires an authenticated connection |
T | : | struct | |
T | : | NetworkMessage |
void NobleConnect.Mirror.NobleClient.RegisterHandler< T > | ( | Action< T > | handler, |
bool | requireAuthentication = true |
||
) |
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.
T | Message type |
handler | Function handler which will be invoked when this message type is received. |
requireAuthentication | True if the message requires an authenticated connection |
T | : | struct | |
T | : | NetworkMessage |
void NobleConnect.Mirror.NobleClient.ReplaceHandler< T > | ( | Action< NetworkConnection, T > | handler, |
bool | requireAuthentication = true |
||
) |
Replaces a handler for a particular message type.
See also RegisterHandler(T)(Action(NetworkConnection, T), bool)
T | Message type |
handler | Function handler which will be invoked when this message type is received. |
requireAuthentication | True if the message requires an authenticated connection |
T | : | struct | |
T | : | NetworkMessage |
void NobleConnect.Mirror.NobleClient.ReplaceHandler< T > | ( | Action< T > | handler, |
bool | requireAuthentication = true |
||
) |
Replaces a handler for a particular message type.
See also RegisterHandler(T)(Action(NetworkConnection, T), bool)
T | Message type |
handler | Function handler which will be invoked when this message type is received. |
requireAuthentication | True if the message requires an authenticated connection |
T | : | struct | |
T | : | NetworkMessage |
void NobleConnect.Mirror.NobleClient.Send< T > | ( | T | message, |
int | channelId = Channels.DefaultReliable |
||
) |
This sends a network message with a message Id to the server. This message is sent on channel zero, which by default is the reliable channel.
The message must be an instance of a class derived from MessageBase.
The message id passed to Send() is used to identify the handler function to invoke on the server when the message is received.
T | The message type to unregister. |
message | |
channelId |
T | : | struct | |
T | : | NetworkMessage |
void NobleConnect.Mirror.NobleClient.SetConnectPort | ( | ushort | port | ) |
void NobleConnect.Mirror.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.
bool NobleConnect.Mirror.NobleClient.UnregisterHandler< T > | ( | ) |
Unregisters a network message handler.
T | The message type to unregister. |
T | : | struct | |
T | : | NetworkMessage |
void NobleConnect.Mirror.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.
bool NobleConnect.Mirror.NobleClient.active => NetworkClient.active |
active is true while a client is connecting/connected (= while the network is active)
NetworkConnection NobleConnect.Mirror.NobleClient.connection => NetworkClient.connection |
The rest of this is just a wrapper for Mirror's NetworkClient.
The NetworkConnection object this client is using.
bool NobleConnect.Mirror.NobleClient.ForceRelayOnly |
Store force relay so that we can pass it on to the iceController
bool NobleConnect.Mirror.NobleClient.isConnected => NetworkClient.isConnected |
This gives the current connection status of the client.
bool NobleConnect.Mirror.NobleClient.isConnecting = false |
A convenient way to check if a connection is in progress
bool NobleConnect.Mirror.NobleClient.isLocalClient => NetworkClient.isLocalClient |
NetworkClient can connect to local server in host mode too
|
getset |
You can check this in OnClientConnect(), it will either be Direct, Punchthrough, or Relay.