Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Resolved Fusion cannot connect with Client in UGS, firewall problem?

Discussion in 'Multiplayer' started by tony040209_unity, Dec 2, 2022.

  1. tony040209_unity

    tony040209_unity

    Joined:
    Mar 21, 2021
    Posts:
    25
    Use this github example to modify:
    https://github.com/Unity-Technologies/com.unity.services.samples.matchplay

    Connection process:
    Mainly after matching two players into the room through UGS MatchMaker,
    The room will actually create two Network objects,
    Respectively a Server and a Client,
    Indicates that the player has been matched into the room,
    So when I create a Network object,
    Let both Server and Client create the same session through Fusion,
    Server and Client connect through Fusion.
    (The Network object mentioned in the content, here refers to the NO of UGS)

    It is feasible to test the current process locally,
    But after the server is placed in UGS and started,
    Also make sure Fusiton is running correctly on UGS,
    For unknown reasons, currently the Server and Client cannot connect with Fusion.

    I suspect it is the firewall settings,
    Does UGS need to set up a firewall?



    FusionCode
    Photon_Manager.cs
    Code (CSharp):
    1.     public void ServerMode()
    2.     {
    3.         StartServer();
    4.         //StartSimulation("TestSession", "jp");
    5.         Debug.Log("Server start");
    6.     }
    7.  
    8.     public void ClientMode()
    9.     {
    10.         StartClient();
    11.         Debug.Log("Client start");
    12.     }
    13.  
    14.  
    15.     async void StartServer()
    16.     {
    17.         _runner = gameObject.AddComponent<NetworkRunner>();
    18.         _runner.ProvideInput = true;
    19.         Debug.Log("open TestSession");
    20.  
    21.         var photonSettings = PhotonAppSettings.Instance.AppSettings.GetCopy();
    22.         photonSettings.FixedRegion = "ASIA".ToLower();
    23.         Debug.Log(photonSettings.FixedRegion + "Regional connection");
    24.  
    25.         var result = await _runner.StartGame(new StartGameArgs()
    26.         {
    27.             GameMode = GameMode.Server,
    28.             SessionName = "TestSession",
    29.             //Scene = SceneManager.GetActiveScene().buildIndex,
    30.             SceneManager = gameObject.AddComponent<NetworkSceneManagerDefault>(),
    31.             CustomPhotonAppSettings = photonSettings,
    32.         });
    33.         if (result.Ok == false) { Debug.LogWarning("FusionServer fail: "+ result.ShutdownReason); }
    34.         else { Debug.Log("FusionServer success"); }
    35.     }
    36.  
    37.     async void StartClient()
    38.     {
    39.         _runner = gameObject.AddComponent<NetworkRunner>();
    40.         _runner.ProvideInput = true;
    41.         Debug.Log("open TestSession");
    42.         var result = await _runner.StartGame(new StartGameArgs()
    43.         {
    44.             GameMode = GameMode.Client,
    45.             SessionName = "TestSession",
    46.             //Scene = SceneManager.GetActiveScene().buildIndex,
    47.             SceneManager = gameObject.AddComponent<NetworkSceneManagerDefault>(),
    48.         });
    49.         if (result.Ok == false) { Debug.LogWarning("FusionClient fail: " + result.ShutdownReason); }
    50.         else { Debug.Log("FusionClient success"); }
    51.     }

    MatchMakerCode

    Code (CSharp):
    1. using Matchplay.Client;
    2. using Matchplay.Networking;
    3. using Matchplay.Shared;
    4. using Matchplay.Shared.Tools;
    5. using Unity.Netcode;
    6. using UnityEngine;
    7.  
    8. namespace Matchplay.Server
    9. {
    10.     /// <summary>
    11.     /// Currently there is no control for moving the player around, only the server does.
    12.     /// The NetworkManager spawns this in automatically, as it is on the designated player object.
    13.     /// </summary>
    14.     public class Matchplayer : NetworkBehaviour
    15.     {
    16.         [HideInInspector]
    17.         public NetworkVariable<Color> PlayerColor = new NetworkVariable<Color>();
    18.         [HideInInspector]
    19.         public NetworkVariable<NetworkString> PlayerName = new NetworkVariable<NetworkString>();
    20.         [SerializeField]
    21.         RendererColorer m_ColorSwitcher;
    22.  
    23.         public override void OnNetworkSpawn()
    24.         {
    25.             if (IsServer && !IsHost)
    26.             {
    27.                 Photon_Manager.Instance.ServerMode(); //PhotonServer connect
    28.             }
    29.             if (IsServer && !IsHost)
    30.                 return;
    31.             if (IsOwner && IsClient && !IsHost)
    32.             {
    33.                 Photon_Manager.Instance.ClientMode(); //PhotonClient connect
    34.             }
    35.             SetColor(Color.black, PlayerColor.Value);
    36.             PlayerColor.OnValueChanged += SetColor;
    37.             ClientSingleton.Instance.Manager.AddMatchPlayer(this);
    38.         }
    39.  
    40.         void SetColor(Color oldColor, Color newColor)
    41.         {
    42.             if (oldColor == newColor)
    43.                 return;
    44.  
    45.             m_ColorSwitcher.SetColor(newColor);
    46.         }
    47.  
    48.         public override void OnNetworkDespawn()
    49.         {
    50.             if (IsServer && !IsHost)
    51.                 return;
    52.             if (ApplicationData.IsServerUnitTest)
    53.                 return;
    54.  
    55.             ClientSingleton.Instance.Manager.RemoveMatchPlayer(this);
    56.         }
    57.     }
    58. }
     
    Last edited: Dec 2, 2022
  2. ramonsmelo

    ramonsmelo

    Joined:
    Jul 31, 2017
    Posts:
    36
  3. tony040209_unity

    tony040209_unity

    Joined:
    Mar 21, 2021
    Posts:
    25
    Thanks, i found the reason.
    Settings vary by region