/// <summary> /// Start a client in LAN only mode. No relays or punchthrough will be used. /// </summary> /// <remarks> /// You will need the host's LAN ip to connect using this method. /// </remarks> /// <param name="hostEndPoint"></param> public void StartClientLANOnly(IPEndPoint hostEndPoint) { isLANOnly = true; isNetworkActive = true; modeProperty.SetValue(this, NetworkManagerMode.ClientOnly); initSingletonMethod.Invoke(this, null); if (authenticator != null) { authenticator.OnStartClient(); authenticator.OnClientAuthenticated.AddListener(onClientAuthenticated); } if (runInBackground) { Application.runInBackground = true; } if (client != null) { client.Dispose(); } client = new NobleClient(); RegisterClientHandlers(); client.Connect(hostEndPoint, isLANOnly); OnStartClient(); }
IEnumerator StopClientAfterDelay(NetworkConnection conn) { isDisconnecting = true; yield return(new WaitForSeconds(40 / 1000.0f)); base.OnClientDisconnect(conn); client.Dispose(); client = null; isDisconnecting = false; }
/// <summary>Stop the client.</summary> /// <remarks> /// In most cases it is not recommended to call this method to disconnect the client as it will /// cause a timeout on the host. You should instead call client.connection.Disconenct() /// to send a disconnect message to the host and disconnect cleanly. /// </remarks> new public void StopClient() { base.StopClient(); if (client != null) { if (client.connection != null) { client.connection.InvokeHandler(new DisconnectMessage(), -1); } client.Dispose(); } client = null; }
/// <summary>Connect to a HostEndPoint, utilizing the Noble Connect relay and punchthrough services.</summary> public void StartClient(IPEndPoint hostEndPoint) { isLANOnly = false; isNetworkActive = true; modeProperty.SetValue(this, NetworkManagerMode.ClientOnly); initSingletonMethod.Invoke(this, null); if (authenticator != null) { authenticator.OnStartClient(); authenticator.OnClientAuthenticated.AddListener(onClientAuthenticated); } if (runInBackground) { Application.runInBackground = true; } if (client == null) { try { InitClient(); } catch (SocketException) { Logger.Log("Failed to resolve relay server address. Starting in LAN only mode", Logger.Level.Warn); isLANOnly = true; client = new NobleClient(); } } RegisterClientHandlers(); client.Connect(hostEndPoint, isLANOnly); OnStartClient(); }
/// <summary> /// Initialize the NobleClient and allocate a relay. /// </summary> /// <remarks> /// You can call as soon as you know that the player intends to connect to host or even as soon as your game is launched. /// Initializing takes a few seconds, so doing it early can make connections seem quicker. /// If you do not call this method it will be called for you when you try and connect. /// </remarks> public void InitClient() { client = new NobleClient(region, OnFatalError, relayLifetime, relayRefreshTime, relayRefreshTimeout, maxRelayRefreshAttempts); client.ForceRelayOnly = forceRelayConnection; client.PrepareToConnect(); }