Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Unity Multiplayer MatchMaker issue : Working from the same PC, not working from different PC ?!?

Discussion in 'Connected Games' started by Feydwin, Jun 29, 2015.

  1. Feydwin

    Feydwin

    Joined:
    Jan 11, 2013
    Posts:
    159
    HI all.

    While pulling my hair trying to make this all work , i just found out something.. weird ?

    Basically, from the same pc, i can launch two different client, start matchmaker, create a match, the second build joins it , all good.

    When i try from two differrent PC : I am getting Timeouts from the client... it sees the match, try to connect to the host, timeouts.

    Any idea ? Before i give up and simply try another network solution ?
     
  2. Feydwin

    Feydwin

    Joined:
    Jan 11, 2013
    Posts:
    159
    SO i have put the network manager to Developer Output. And this is what i get :

    Code (CSharp):
    1. Client Relay Slot Id: -1
    2. UnityEngine.Networking.NetworkClient:Connect(MatchInfo)
    3. ManNetwork:MatchJoined(JoinMatchResponse) (at Assets/XLink Assets/Scripts/Network/ManNetwork.cs:102)
    4. UnityEngine.Networking.Match.<ProcessMatchResponse>c__Iterator0`1:MoveNext()
    5.  
    6. Client event: host=0 event=DisconnectEvent error=6
    7. UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
    8.  
    9. Client disconnected
    10. UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
    11.  
    12.  
    And then a big " Client Disconnect" ...

    Coud still use some help, please....
     
  3. Feydwin

    Feydwin

    Joined:
    Jan 11, 2013
    Posts:
    159
    Alright... I could seriously use some help here...

    I managed to narrowed it down a little bit ...

    The connection between the two PC works when i am using the NetworkManagedHud component, with the runtime GUI.
    But when i try my own Match Script, that s when it fails. And something is missing when i do it with my script.
    So : This is a screen of both the HUDs :
    WTF.jpg

    And here is my code :
    Code (CSharp):
    1. void Start ()
    2.     {
    3.         StartMatchMaker() ;
    4.         networkMatch = GetComponent<NetworkMatch>();
    5.         UnityEngine.Networking.Types.AppID appid = (UnityEngine.Networking.Types.AppID)41551;
    6.         networkMatch.SetProgramAppID(appid);  
    7.     }
    8.  
    9.     //Start the 1v1 Matcher
    10.     public void Start1V1 ()
    11.     {
    12.         networkMatch.ListMatches(0, 20, "", ListMatch);  
    13.     }
    14.  
    15.     public void ListMatch(ListMatchResponse matchListResponse)
    16.     {
    17.         if (matchListResponse.success && matchListResponse.matches != null)
    18.         {
    19.             matchList = matchListResponse.matches ;
    20.             matchCount = matchList.Count ;
    21.  
    22.             //No Match Found
    23.             if (matchList.Count == 0)
    24.             {
    25.                 CreateMatch() ;
    26.             }
    27.             else
    28.             {
    29.                 FindAMatch () ;
    30.             }          
    31.         }
    32.     }
    33.  
    34.     public void CreateMatch ()
    35.     {
    36.         CreateMatchRequest create = new CreateMatchRequest();
    37.         create.name = "TestMatch" ;
    38.         create.size = 2 ;
    39.         create.advertise = true ;
    40.         create.password = "" ;
    41.         networkMatch.CreateMatch(create, MatchCreated);
    42.     }
    43.  
    44.     public void MatchCreated (CreateMatchResponse matchResponse)
    45.     {
    46.         if (matchResponse.success)
    47.         {
    48.             matchCreated = true ;
    49.             Utility.SetAccessTokenForNetwork(matchResponse.networkId, new NetworkAccessToken(matchResponse.accessTokenString));
    50.             NetworkServer.Listen(new MatchInfo(matchResponse), 9000);
    51.             Start1V1AsHost() ;
    52.         }
    53.         else
    54.         {
    55.             print ("Failed during Match Creation") ;
    56.         }  
    57.     }
    58.  
    59.     public void FindAMatch()
    60.     {
    61.         networkMatch.JoinMatch(matchList[0].networkId, "", MatchJoined);
    62.     }
    63.  
    64.     public void MatchJoined (JoinMatchResponse matchJoin)
    65.     {
    66.         if (matchJoin.success)
    67.         {
    68.             matchJoined = true ;  
    69.             Utility.SetAccessTokenForNetwork(matchJoin.networkId, new NetworkAccessToken(matchJoin.accessTokenString));
    70.             NetworkClient myClient = new NetworkClient();
    71.             myClient.RegisterHandler(MsgType.Connect, OnConnected);
    72.             myClient.Connect(new MatchInfo(matchJoin));
    73.         }
    74.         else
    75.         {
    76.             print("Failed to Join Match") ;
    77.         }  
    78.     }
    79.  
    80.     public void OnConnected(NetworkMessage msg)
    81.     {
    82.         StartClient() ;  
    83.     }
    84.  
    85.     public void Start1V1AsHost ()
    86.     {
    87.         StartHost() ;
    88.         controller.hosting = true ;
    89.         controller.StartCoroutine("Start1V1") ;  
    90.     }
    91.  
    92.     //When Player Prefab gets Created
    93.     public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
    94.     {
    95.         controller.playersInGame ++ ;
    96.         var player = (GameObject)GameObject.Instantiate(playerPrefab, new Vector3(0,0,0) , Quaternion.identity);
    97.         if (controller.playersInGame == 1) { player.GetComponent<NetPlayer>().team = 1 ; }
    98.         if (controller.playersInGame == 2) { player.GetComponent<NetPlayer>().team = 2 ; }
    99.         NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
    100.     }
    I am getting desperate here...
     
    Raiden-Freeman likes this.
  4. Feydwin

    Feydwin

    Joined:
    Jan 11, 2013
    Posts:
    159
    Found it...

    modified for :

    matchInfo = new MatchInfo(matchResponse);
    Utility.SetAccessTokenForNetwork(matchResponse.networkId, new NetworkAccessToken(matchResponse.accessTokenString));
    StartHost(matchInfo) ;

    and :

    matchJoined = true ;
    matchInfo = new MatchInfo(matchJoin);
    Utility.SetAccessTokenForNetwork(matchJoin.networkId, new NetworkAccessToken(matchJoin.accessTokenString));;
    StartClient(matchInfo) ;


    Thanks JetBrains.dotPeek
     
  5. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,919
    Please report this as a bug (pretty sure it is).
     
  6. clarson2974

    clarson2974

    Joined:
    Aug 24, 2015
    Posts:
    16
    On Unity 5.2.0f3 and I had this exact same problem, and was able to resolve with what you put in your post. You saved me a lot of headache, so thank you!
     
  7. ben-maurin

    ben-maurin

    Joined:
    Apr 7, 2016
    Posts:
    47
    Thank you Feydwin ! saved me lot of time