Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Failed To Connect Server even after Matchmaker found and match two tickets

Discussion in 'Matchmaker' started by tyranyuwen, Sep 24, 2023.

  1. tyranyuwen

    tyranyuwen

    Joined:
    May 24, 2016
    Posts:
    1
    Hello, first time posting and looking for advice on where i went wrong. Also using Netcode for Game Objects and Unity's Multiplay services for the first time and pretty new to network programming in general.

    I got the Matchmaker and game server hosting setup following guides and resources on the Internet. However even though its successful in finding and matching tickets between two devices. The server would not move to the next game scene and eventually would debug out a Failed to Connect To Server Error.




    The codeblock below is what should run in the server build for the game to move to the next scene after a match is found and also the Initialization for the server and client build to connect to the Game server hosting.


    Code (CSharp):
    1. private void MultiplayEventCallbacks_Allocate(MultiplayAllocation obj)
    2.     {
    3.         Debug.Log("DEDICATED_SERVER MultiplayEventCallbacks_Allocate");
    4.  
    5.         if (alreadyAutoAllocated) {
    6.             Debug.Log("Already auto allocated!");
    7.             return;
    8.         }
    9.  
    10.         SetupBackfillTickets();
    11.  
    12.         alreadyAutoAllocated = true;
    13.  
    14.         var serverConfig = MultiplayService.Instance.ServerConfig;
    15.         Debug.Log($"Server ID[{serverConfig.ServerId}]");
    16.         Debug.Log($"AllocationID[{serverConfig.AllocationId}]");
    17.         Debug.Log($"Port[{serverConfig.Port}]");
    18.         Debug.Log($"QueryPort[{serverConfig.QueryPort}]");
    19.         Debug.Log($"LogDirectory[{serverConfig.ServerLogDirectory}]");
    20.  
    21.         string ipv4Address = "0.0.0.0";
    22.         ushort port = serverConfig.Port;
    23.         NetworkManager.Singleton.GetComponent<UnityTransport>().SetConnectionData(ipv4Address, port, "0.0.0.0");
    24.  
    25.         GameMultiplayer.Instance.StartServer();
    26.         Loader.LoadNetwork(Loader.Scene.CharacterSelectScene);
    27.     }
    28. private async void InitializeUnityAuthentication()
    29.     {
    30.         if (UnityServices.State != ServicesInitializationState.Initialized)
    31.         {
    32.             InitializationOptions initializationOptions = new InitializationOptions();
    33. #if !DEDICATED_SERVER
    34.             initializationOptions.SetProfile(UnityEngine.Random.Range(0, 10000).ToString());
    35. #endif
    36.  
    37.             await UnityServices.InitializeAsync(initializationOptions);
    38.  
    39. #if !DEDICATED_SERVER
    40.             await AuthenticationService.Instance.SignInAnonymouslyAsync();
    41. #endif
    42.  
    43. #if DEDICATED_SERVER
    44.             Debug.Log("DEDICATED_SERVER LOBBY");
    45.  
    46.             MultiplayEventCallbacks multiplayEventCallbacks = new MultiplayEventCallbacks();
    47.             multiplayEventCallbacks.Allocate += MultiplayEventCallbacks_Allocate;
    48.             multiplayEventCallbacks.Deallocate += MultiplayEventCallbacks_Deallocate;
    49.             multiplayEventCallbacks.Error += MultiplayEventCallbacks_Error;
    50.             multiplayEventCallbacks.SubscriptionStateChanged += MultiplayEventCallbacks_SubscriptionStateChanged;
    51.             IServerEvents serverEvents = await MultiplayService.Instance.SubscribeToServerEventsAsync(multiplayEventCallbacks);
    52.  
    53.             serverQueryHandler = await MultiplayService.Instance.StartServerQueryHandlerAsync(4, "MyServerName", "KingOfTheArena", "5.6", "Default");
    54.  
    55.             var serverConfig = MultiplayService.Instance.ServerConfig;
    56.             if (serverConfig.AllocationId != "") {
    57.                 // Already Allocated
    58.                 MultiplayEventCallbacks_Allocate(new MultiplayAllocation("", serverConfig.ServerId, serverConfig.AllocationId));
    59.             }
    60. #endif
    61.         }
    62.         else
    63.         {
    64.             // Already Initialized
    65. #if DEDICATED_SERVER
    66.             Debug.Log("DEDICATED_SERVER LOBBY - ALREADY INIT");
    67.  
    68.             var serverConfig = MultiplayService.Instance.ServerConfig;
    69.             if (serverConfig.AllocationId != "") {
    70.                 // Already Allocated
    71.                 MultiplayEventCallbacks_Allocate(new MultiplayAllocation("", serverConfig.ServerId, serverConfig.AllocationId));
    72.             }
    73. #endif
    74.  
    75.  
    76.         }
    77.     }
    If i am lacking in context, i would appreciate in being pointed out.
     

    Attached Files:

  2. Awesomeplayer98

    Awesomeplayer98

    Joined:
    Dec 8, 2023
    Posts:
    2
    Did you ever figure it out? I still can't find out what the heck MultiplayEventCallbacks_Allocate is and this was the single result on Google.