/// <summary> /// This starts a network "host" - a server and client in the same application. /// <para>The client returned from StartHost() is a special "local" client that communicates to the in-process server using a message queue instead of the real network. But in almost all other cases, it can be treated as a normal client.</para> /// </summary> public async Task StartHost() { // StartHost is inherently ASYNCHRONOUS (=doesn't finish immediately) // // Here is what it does: // Listen // ConnectHost // if onlineScene: // LoadSceneAsync // ... // FinishLoadSceneHost // FinishStartHost // SpawnObjects // StartHostClient <= not guaranteed to happen after SpawnObjects if onlineScene is set! // ClientAuth // success: server sends changescene msg to client // else: // FinishStartHost // // there is NO WAY to make it synchronous because both LoadSceneAsync // and LoadScene do not finish loading immediately. as long as we // have the onlineScene feature, it will be asynchronous! // setup server first await SetupServer(); client.ConnectHost(server); // call OnStartHost AFTER SetupServer. this way we can use // NetworkServer.Spawn etc. in there too. just like OnStartServer // is called after the server is actually properly started. OnStartHost.Invoke(); FinishStartHost(); }
/// <summary> /// This starts a network "host" - a server and client in the same application. /// <para>The client returned from StartHost() is a special "local" client that communicates to the in-process server using a message queue instead of the real network. But in almost all other cases, it can be treated as a normal client.</para> /// </summary> public async Task StartHost() { // setup server first await SetupServer(); client.ConnectHost(server); // call OnStartHost AFTER SetupServer. this way we can use // NetworkServer.Spawn etc. in there too. just like OnStartServer // is called after the server is actually properly started. OnStartHost.Invoke(); logger.Log("NetworkManager StartHost"); }
/// <summary> /// This starts a network "host" - a server and client in the same application. /// <para>The client returned from StartHost() is a special "local" client that communicates to the in-process server using a message queue instead of the real network. But in almost all other cases, it can be treated as a normal client.</para> /// </summary> public async Task StartHost(NetworkClient client) { if (!client) { throw new InvalidOperationException("NetworkClient not assigned. Unable to StartHost()"); } // start listening to network connections await ListenAsync(); client.ConnectHost(this); ActivateHostScene(); // call OnStartHost AFTER SetupServer. this way we can use // NetworkServer.Spawn etc. in there too. just like OnStartServer // is called after the server is actually properly started. OnStartHost.Invoke(); logger.Log("NetworkManager StartHost"); }