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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unet Timeouts

Discussion in 'UNet' started by sebeisdrache, Jul 24, 2015.

  1. sebeisdrache

    sebeisdrache

    Joined:
    Jan 16, 2015
    Posts:
    34
    Hello,

    I've remake may whole netcode with the new Unet API.

    But now there is a problem, The game disappers form the matchmaking list and connected clients will also disconnected because of a Timeout, but the server is still running:


    I've tested like this:
    Server and host on the same machine (Unity Editor + Build).

    should there additonal options or is this a bug in Unity?
     
    Srimavo likes this.
  2. sebeisdrache

    sebeisdrache

    Joined:
    Jan 16, 2015
    Posts:
    34
    sorry for double posting

    here is the Code of my game menu (only in the offline scene).

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Networking;
    3. using UnityEngine.Networking.Types;
    4. using UnityEngine.Networking.Match;
    5. using UnityEngine.UI;
    6. using System.Collections;
    7. using System.Collections.Generic;
    8.  
    9. public class GameMenuController : MonoBehaviour {
    10.  
    11.     public GameObject mainUI;
    12.     public GameObject popup;
    13.     public GameObject serverButtonPrefab;
    14.     public GameObject loadingScreenPrefab;
    15.  
    16.     MatchDesc matchToJoin;
    17.  
    18.     void Awake () {
    19.         Tools.UnLockCursor();
    20.         Tools.mainUI = mainUI;
    21.         Tools.popup = popup;
    22.         Tools.menu = false;
    23.  
    24.         Connection.password = "";
    25.  
    26.         Tools.maps.Clear();
    27.  
    28.         Tools.maps.Add("NetTest");
    29.  
    30.         Connection.map = "NetTest";
    31.  
    32.         if(PlayerPrefs.GetString("cliendId") == string.Empty || PlayerPrefs.GetString("cliendId") == "")
    33.         {
    34.             string pool = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    35.             string random = string.Empty;
    36.             for(int i = 0; i < 100; i++)
    37.             {
    38.                 random += pool[Random.Range(0, pool.Length)];
    39.             }
    40.             PlayerPrefs.SetString("cliendId", random);
    41.         }
    42.     }
    43.  
    44.     void Start()
    45.     {
    46.         if(Connection.msg != null)
    47.         {
    48.             Tools.popmsg(Connection.msgHeader, Connection.msg);
    49.             Connection.msgHeader = null;
    50.             Connection.msg = null;
    51.         }
    52.         NetworkManager.singleton.StartMatchMaker();
    53.     }
    54.  
    55.     void Update()
    56.     {
    57.         NetworkManager.singleton.onlineScene = Connection.map;
    58.     }
    59.  
    60.     public void SetMatchName(InputField input)
    61.     {
    62.         Connection.gameName = input.text;
    63.     }
    64.  
    65.     public void SetMatchPassword(InputField input)
    66.     {
    67.         Connection.password = input.text;
    68.     }
    69.  
    70.     public void StartHost()
    71.     {
    72.         CreateMatchRequest request = new CreateMatchRequest();
    73.  
    74.         request.name = Connection.gameName;
    75.         request.size = Connection.maxPlayers;
    76.         request.password = Connection.password;
    77.  
    78.         Tools.SetLoadingScreen(loadingScreenPrefab);
    79.         Tools.SetLoadingScreenInfo(Lang.GetString("LoadingScreenWaitForData"), 0.0f);
    80.  
    81.         NetworkManager.singleton.matchMaker.CreateMatch(request, OnMatchCreate);
    82.     }
    83.  
    84.     void OnMatchCreate(CreateMatchResponse matchResponse)
    85.     {
    86.         if(matchResponse.success)
    87.         {
    88.             MatchInfo info =  new MatchInfo(matchResponse);
    89.  
    90.             Tools.SetLoadingScreenInfo(Lang.GetString("LoadingScreenLoadMap"), 0.1f);
    91.             Utility.SetAccessTokenForNetwork(matchResponse.networkId, new NetworkAccessToken(matchResponse.accessTokenString));
    92.  
    93.             //NetworkServer.Listen(info, NetworkManager.singleton.networkPort);
    94.  
    95.             NetworkManager.singleton.StartHost(info);
    96.         }
    97.         else
    98.         {
    99.             Tools.UnSetLoadingScreen();
    100.         }
    101.     }
    102.  
    103.     public void GetHostList()
    104.     {
    105.         mainUI.transform.Find("ServerList").gameObject.SetActive(true);
    106.  
    107.         ListMatchRequest request = new ListMatchRequest();
    108.         request.includePasswordMatches = true;
    109.         request.pageSize = 10000;
    110.         request.nameFilter = "";
    111.         NetworkManager.singleton.matchMaker.ListMatches(request, OnMatchList);
    112.  
    113.     }
    114.  
    115.     void OnMatchList(ListMatchResponse res)
    116.     {
    117.         if(res.success)
    118.         {
    119.             UpdateMatchList(res.matches);
    120.         }
    121.     }
    122.  
    123.     void UpdateMatchList(List<MatchDesc> matches){
    124.  
    125.         GameObject serverListPanel = mainUI.transform.FindChild("ServerList/ScrollArea/ScrollContent").transform.gameObject;
    126.  
    127.         Tools.ClearChildren(serverListPanel);
    128.  
    129.         for(int i = 0; i < matches.Count; i++)
    130.         {
    131.             GameObject newButton = Instantiate (serverButtonPrefab) as GameObject;
    132.             ServerButton button = newButton.GetComponent <ServerButton> ();
    133.             button.match = matches[i];
    134.             button.gameMenuController = this;
    135.             Debug.Log(matches[i]);
    136.             newButton.transform.SetParent (serverListPanel.transform);
    137.         }
    138.  
    139.     }
    140.  
    141.     public void JoinDialog(MatchDesc match)
    142.     {
    143.  
    144.         GameObject joinDialog = mainUI.transform.Find("JoinDialog").transform.gameObject;
    145.         GameObject joinDialogPasswordField = mainUI.transform.FindChild("JoinDialog/ScrollArea/ScrollContent/Password").transform.gameObject;
    146.  
    147.         Text joinDialogName = mainUI.transform.FindChild("JoinDialog/ScrollArea/ScrollContent/Name/Name").transform.GetComponent<Text>();
    148.         Text joinDialogMap = mainUI.transform.FindChild("JoinDialog/ScrollArea/ScrollContent/Map/Map").transform.GetComponent<Text>();
    149.  
    150.         joinDialog.SetActive(true);
    151.         joinDialog.GetComponent<RectTransform>().SetAsLastSibling();
    152.    
    153.         joinDialogPasswordField.SetActive(true);
    154.        
    155.         joinDialogName.text = match.name;
    156.         joinDialogMap.text = "";
    157.  
    158.         matchToJoin = match;
    159.        
    160.     }
    161.  
    162.     public void JoinMatch()
    163.     {
    164.         Debug.Log("Joning Server");
    165.         Tools.SetLoadingScreen(loadingScreenPrefab);
    166.         Tools.SetLoadingScreenInfo(Lang.GetString("LoadingScreenWaitForData"), 0.0f);
    167.  
    168.         JoinMatchRequest request = new JoinMatchRequest();
    169.  
    170.         request.networkId = matchToJoin.networkId;
    171.         request.password = Connection.password;
    172.  
    173.         NetworkManager.singleton.matchMaker.JoinMatch(request, OnJoinMatch);
    174.  
    175.     }
    176.  
    177.     void OnJoinMatch(JoinMatchResponse matchJoin)
    178.     {
    179.         if(matchJoin.success)
    180.         {
    181.             Tools.SetLoadingScreenInfo(Lang.GetString("LoadingScreenLoadMap"), 0.1f);
    182.  
    183.             Utility.SetAccessTokenForNetwork(matchJoin.networkId, new NetworkAccessToken(matchJoin.accessTokenString));
    184.  
    185.             NetworkManager.singleton.StartClient(new MatchInfo(matchJoin));
    186.             /*
    187.             NetworkClient myClient = new NetworkClient();
    188.             myClient.RegisterHandler(MsgType.Connect, OnConnected);
    189.             myClient.Connect(new MatchInfo(matchJoin));
    190.             */
    191.         }
    192.         else
    193.         {
    194.             Tools.UnSetLoadingScreen();
    195.         }
    196.     }
    197.     /*
    198.     public void OnConnected(NetworkMessage msg)
    199.     {
    200.         NetworkManager.singleton.StartClient();
    201.     }
    202.     */
    203.     public void Quit()
    204.     {
    205.         Application.Quit();
    206.     }
    207.  
    208. }
    209.  
     
  3. JeremyUnity

    JeremyUnity

    Unity Technologies

    Joined:
    Mar 4, 2014
    Posts:
    147
    Azurne and akuno like this.
  4. sebeisdrache

    sebeisdrache

    Joined:
    Jan 16, 2015
    Posts:
    34
    Possible, but i have just a test map with a few spawned objects.

    Is it possible to adjust the limiters values?
     
  5. sebeisdrache

    sebeisdrache

    Joined:
    Jan 16, 2015
    Posts:
    34
    sorry for double posting but, now I have tested this on two differnt machines over the internent.

    please have a look at the attached picture
     

    Attached Files:

  6. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    Do you work via relay server or do you have direct connection between clients?
     
  7. sebeisdrache

    sebeisdrache

    Joined:
    Jan 16, 2015
    Posts:
    34
    I'm using the relay server

    the console ouput when I joining a game:
    Code (CSharp):
    1. JSON Response: [[UnityEngine.Networking.Match.JoinMatchResponse]-success:True-extendedInfo:]-address:52.28.24.148,port:9999,networkId:0x0010000000003FD2,nodeId:0x6A8C,usingRelay:True
    2. UnityEngine.Networking.Match.<ProcessMatchResponse>c__Iterator0`1:MoveNext()
    I start the host with the code in my post above.

    what is needed to tell unity to not use a relay server?

    edit:

    is there a way to use the matchmaking system more like the old masterserver system?

    I have tested the situation:

    2players (1 host and 1 client) can idle around and doing nothing then standing around, but if the players do something (spawning objects, moving around) the timeout comes.
    But i need to transfer the data to have the multiplayer experience.

    Wireshark output has an avg packet size 60 between 180 bit with some rare peaks with 600 between 800.
     
    Last edited: Aug 6, 2015
  8. sebeisdrache

    sebeisdrache

    Joined:
    Jan 16, 2015
    Posts:
    34
    any solutions?
     
  9. LevonRavel

    LevonRavel

    Joined:
    Feb 26, 2014
    Posts:
    177
    I use to have this problem with my networking package Cross.Net, The fix for it is simple you have to ready the connection for the player connecting to the game. Everyone that joins should ask ClientScene.Ready this will fix your issue..
     
  10. sebeisdrache

    sebeisdrache

    Joined:
    Jan 16, 2015
    Posts:
    34
    how i have to use ClientScene.Ready?

    on a client after joinig the game:

    like:

    void OnConnected()
    {
    ClientScene.Ready();
    }

    ?
     
  11. LevonRavel

    LevonRavel

    Joined:
    Feb 26, 2014
    Posts:
    177
    I am not even using the Network Manager that unity provides instead im going about it in a different fashion..

    Code (CSharp):
    1. public void CreateMatch()
    2. {
    3.         NetworkServer.Listen(SomePort);
    4.         ServerCallBacks ();
    5.                  
    6.         client = ClientScene.ConnectLocalServer();
    7.         ClientCallBacks ();
    8. }
    9.  
    10. void ClientCallBacks ()
    11. {
    12.         client.RegisterHandler(MsgType.Connect, CConnect);
    13. }
    14.  
    15. void ServerCallBacks ()
    16. {
    17.         NetworkServer.RegisterHandler(MsgType.Connect, SConnect)
    18. }
    19.  
    20. void CConnect(NetworkMessage msg)
    21. {
    22.         ClientScene.Ready(client.connection);
    23. }
    24.  
    25. void SConnect(NetworkMessage msg)
    26. {
    27.         Debug.Log("Client Connected");
    28. }
    29.  
    from here you can register more handlers and have .Ready when the client becomes ready notify that method. you can have .AddPlayer that way when the client request to add the player for connection it will notify that method also.. Hope this helps
     
    Last edited: Aug 19, 2015
  12. sebeisdrache

    sebeisdrache

    Joined:
    Jan 16, 2015
    Posts:
    34
    Now I use the following code in my NetworkManager class

    Code (CSharp):
    1.     public override void OnClientSceneChanged (NetworkConnection conn)
    2.     {
    3.         ClientScene.Ready(conn);
    4.         base.OnClientSceneChanged (conn);
    5.     }
    the I got this output on the servers console
    But i have still a Disconnect after a few actions.

    I think its the hidden bandwith limit of the Unet Masterserver/Matchmatking server?

    If I looking for the server in the Match list, after the "Timeout" : the server is no longer in the list.

    All of my game code is working without any errors like with the old networking system, the only thing is the "timeout".

    edit:

    i have repoted this as Bug, maybe it helps
     
    Last edited: Aug 19, 2015
  13. sebeisdrache

    sebeisdrache

    Joined:
    Jan 16, 2015
    Posts:
    34
    I really want du contiune my development of the game but with these timeouts in a multiplayer game its unplayable.
     
  14. JeremyUnity

    JeremyUnity

    Unity Technologies

    Joined:
    Mar 4, 2014
    Posts:
    147
    It does sound likely you're hitting the bandwidth limiter.

    You could try reducing the amount of data sent to see if the disconnections stop or take longer to happen.
     
  15. LevonRavel

    LevonRavel

    Joined:
    Feb 26, 2014
    Posts:
    177
    Thats not the case, If you looked above at post #11 he is making too many connections,

    sebieisdrache, You need to do it in this order /Ready the connection only once, I highly recommend making the connection after the scene change / Then you need to Add the player for the connection after you have done this you should request the server to instantiate your player. If all was done right then you should be good to go.

    Also try to do a simple connection before trying to integrate the whole project over. I found it easier to understand by doing this.
     
    Last edited: Aug 22, 2015
  16. sebeisdrache

    sebeisdrache

    Joined:
    Jan 16, 2015
    Posts:
    34
    I'm using the unity Networkmanger wich do the ready states by it self when spawning a player.

    Maybe i reach the Bandwidth limit (I cant figure it out, because i don't have the Pro version), but I need these bandwidth like syncing multipe inventorys (lists of items) on different events (wich is working).
    Then sending the active player equipment to each client who joins later.
    Also I need to sync (syncVar) multiple variables like stamina, health, hydration and much more.
    All functions had worked well with the old networking system (no bandwith limit?) and they working well now with the new system but there are timeouts.

    Is there a way to increase the bandwith limit or acting like the old master server system(when the relay sever causes the limits)

    edit:

    why is there a hidden bandwith limit? I dont want to make a "Mobile Game"
     
    Last edited: Aug 22, 2015
  17. tosaki

    tosaki

    Joined:
    Nov 30, 2014
    Posts:
    2
    I have the same problem.
    I just run this↓ manual's sample code.
    http://docs.unity3d.com/Manual/UNetMatchMaker.html

    It can join match, and connect between server and client.
    However, I got a timeout error after few seconds.
    I don't think it's caused by bandwidth limit, but I have no idea...

     
  18. LevonRavel

    LevonRavel

    Joined:
    Feb 26, 2014
    Posts:
    177
    Here is an example that i am using in Cross.Net, There was more involved i stripped as much as I could..

    To create a match with localHost / Server combination you would run
    CreateMatch();

    this will setup the server / local host

    to connect a client to the localhost / server
    ConnectToMatch();

    Code (CSharp):
    1.  
    2.  
    3.    public void ConnectToMatch()
    4.    {
    5.          client.Connect (someIP, somePort));
    6.          ClientCallBacks ();
    7.     }
    8.  
    9. //LocalHost / Server combination
    10.  
    11.    public void CreateMatch()
    12.    {
    13.  
    14. //Start the server
    15.  
    16.      NetworkServer.Listen(SomePort);
    17.  
    18. //Register ServerCallBacks
    19.  
    20.      ServerCallBacks ();
    21.  
    22. //Register the game prefabs
    23.  
    24.      foreach(GameObject i in gameBehaviour.registerPrefabs)
    25.          ClientScene.RegisterPrefab(i);
    26.  
    27. //Create a local client on the created server
    28.  
    29.      client = ClientScene.ConnectLocalServer();
    30.  
    31. //RegisterCallBacks
    32.  
    33.      ClientCallBacks ();
    34.    }
    35.  
    36. //When a client connects the server will fire SConnect <-- as the player has connected''
    37.  
    38.     void ServerCallBacks ()
    39.     {
    40.         NetworkServer.RegisterHandler(MsgType.Connect, SConnect) ;
    41.         NetworkServer.RegisterHandler (MsgType.Disconnect, SDisconnect);
    42.         NetworkServer.RegisterHandler (MsgType.Ready, SReady);
    43.         NetworkServer.RegisterHandler(MsgType.AddPlayer, SAddPlayer);
    44.         NetworkServer.RegisterHandler((short)1000, new NetworkMessageDelegate(SetupPrefab));
    45.         NetworkServer.RegisterHandler((short)1001, new NetworkMessageDelegate(AffirmConnection));
    46.     }
    47.  
    48. //The Client will also fire a CConnect <-- as the client has connected to the server
    49.  
    50. //after this is done we want to run ClientScene.Ready within the CConnect..
    51.  
    52. //from here the server will receive a message from the client SReady
    53.  
    54. //Inside SReady we send a message to the client AffirmConnection as I have found
    55. //that if you AddPlayerForConnection Right after ready the server misses this and doesnt
    56. //actually add teh player.
    57.  
    58.     void ClientCallBacks ()
    59.     {
    60.         client.RegisterHandler(MsgType.Connect, CConnect);
    61.         client.RegisterHandler(MsgType.Disconnect, CDisconnect);
    62.         client.RegisterHandler (MsgType.Ready,CReady);
    63.         client.RegisterHandler((short)1001, new NetworkMessageDelegate(AffirmConnection));
    64.     }
    65.  
    66.     void SConnect(NetworkMessage msg)
    67.     {
    68.         try
    69.         {
    70.             gameBehaviour.connectionCallback.SendMessage ("CrossNetMsg","Server: PlayerConnected");
    71.         }catch{
    72.  
    73.             DebugMessages (" Please make a reference to CrossNetMsg: public void CrossNetMsg(string msg){ do stuff..}");
    74.         }
    75.     }
    76.  
    77.     void SDisconnect(NetworkMessage msg)
    78.     {
    79.         network_connections--;
    80.         NetworkServer.DestroyPlayersForConnection (msg.conn);
    81.  
    82.         try
    83.         {
    84.             gameBehaviour.connectionCallback.SendMessage ("CrossNetMsg","Server: PlayerDisconnected");
    85.         }catch{
    86.  
    87.             DebugMessages (" Please make a reference to CrossNetMsg: public void CrossNetMsg(string msg){ do stuff..}");
    88.         }
    89.     }
    90.  
    91.     void SAddPlayer(NetworkMessage msg)
    92.     {
    93.         try
    94.         {
    95.             gameBehaviour.connectionCallback.SendMessage ("CrossNetMsg","Server: AddedPlayer");
    96.         }catch{
    97.  
    98.             DebugMessages (" Please make a reference to CrossNetMsg: public void CrossNetMsg(string msg){ do stuff..}");
    99.         }
    100.     }
    101.  
    102.     void SReady(NetworkMessage msg)
    103.     {
    104.         NetworkServer.SendToClient(msg.conn.connectionId,(short)1001,(MessageBase)new StringMessage ("Connected"));
    105.         try
    106.         {
    107.             gameBehaviour.connectionCallback.SendMessage ("CrossNetMsg","Server: PlayerReady");
    108.         }catch{
    109.  
    110.             DebugMessages (" Please make a reference to CrossNetMsg: public void CrossNetMsg(string msg){ do stuff..}");
    111.         }
    112.     }
    113.  
    114.     void CAddPlayer(NetworkMessage msg)
    115.     {
    116.         try
    117.         {
    118.             gameBehaviour.connectionCallback.SendMessage ("CrossNetMsg","Client: Requested Add Player");
    119.         }catch{
    120.  
    121.             DebugMessages (" Please make a reference to CrossNetMsg: public void CrossNetMsg(string msg){ do stuff..}");
    122.         }
    123.     }
    124.  
    125.     void CReady(NetworkMessage msg)
    126.     {
    127.         try
    128.         {
    129.             gameBehaviour.connectionCallback.SendMessage ("CrossNetMsg","Client: PlayerReady");
    130.         }catch{
    131.  
    132.             DebugMessages (" Please make a reference to CrossNetMsg: public void CrossNetMsg(string msg){ do stuff..}");
    133.         }
    134.  
    135.    void CConnect(NetworkMessage msg)
    136.    {
    137.   ClientScene.Ready(client.connection);
    138.    }
    139.  
    140.    void CDisconnect(NetworkMessage msg)
    141.    {
    142.      try
    143.      {
    144.        gameBehaviour.connectionCallback.SendMessage ("CrossNetMsg","Client: Disconnected");
    145.      }catch{
    146.  
    147.        DebugMessages (" Please make a reference to CrossNetMsg: public void CrossNetMsg(string msg){ do stuff..}");
    148.      }
    149.  
    150. //This is where the client recieves a message from the server SReady
    151. //I noticed without this if you try to Add A Player for connection sometimes it fails
    152. //as the client wasnt properly ready inside this Handler you would run the
    153. //Add player for connection..
    154.  
    155.   void AffirmConnection(NetworkMessage msg)
    156.   {
    157.   try
    158.   {
    159.   gameBehaviour.connectionCallback.SendMessage("CrossNetMsg", "Client: PlayerConnected");
    160.   }
    161.   catch
    162.   {
    163.   DebugMessages(" Please make a reference to CrossNetMsg: public void CrossNetMsg(string msg){ do stuff..}");
    164.   }
    165.   }
    166.  
    167.     }
    The above code became out of format due to trying to copy and paste around most of the Cross.Net code stuff. Hopefully this will make sense.
     
    Last edited: Aug 23, 2015
  19. tosaki

    tosaki

    Joined:
    Nov 30, 2014
    Posts:
    2
    I found that sending messages Server and Client each other, it can prevents 'UNet Client Disconnect Error: Timeout'.
    Do I have to send keep alive messages when using Unity's match maker?

    Here is my code based on Unity's sample code↓.
    http://docs.unity3d.com/Manual/UNetMatchMaker.html
    Maybe it's not a correct solution though.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Networking;
    3. using UnityEngine.Networking.Types;
    4. using UnityEngine.Networking.Match;
    5. using System.Collections.Generic;
    6.  
    7. public class HostGame : MonoBehaviour
    8. {
    9.     List<MatchDesc> matchList = new List<MatchDesc>();
    10.     bool matchCreated;
    11.     NetworkMatch networkMatch;
    12.     NetworkClient myClient = null;
    13.     string label = "";
    14.     int cnt = 0;
    15.  
    16.     class Message : MessageBase
    17.     {
    18.         public uint s;
    19.  
    20.         // This method would be generated
    21.         public override void Deserialize(NetworkReader reader)
    22.         {
    23.             s = reader.ReadPackedUInt32();
    24.         }
    25.        
    26.         // This method would be generated
    27.         public override void Serialize(NetworkWriter writer)
    28.         {
    29.             writer.WritePackedUInt32(s);
    30.         }
    31.     }
    32.  
    33.     void Awake()
    34.     {
    35.         networkMatch = gameObject.AddComponent<NetworkMatch>();
    36.     }
    37.    
    38.     void OnGUI()
    39.     {
    40.         GUI.Label (new Rect (100, 100, 100, 100), label + cnt);
    41.  
    42.         // You would normally not join a match you created yourself but this is possible here for demonstration purposes.
    43.         if(GUILayout.Button("Create Room"))
    44.         {
    45.             CreateMatchRequest create = new CreateMatchRequest();
    46.             create.name = "NewRoom";
    47.             create.size = 4;
    48.             create.advertise = true;
    49.             create.password = "";
    50.            
    51.             networkMatch.CreateMatch(create, OnMatchCreate);
    52.         }
    53.        
    54.         if (GUILayout.Button("List rooms"))
    55.         {
    56.             networkMatch.ListMatches(0, 20, "", OnMatchList);
    57.         }
    58.        
    59.         if (matchList.Count > 0)
    60.         {
    61.             GUILayout.Label("Current rooms");
    62.         }
    63.         foreach (var match in matchList)
    64.         {
    65.             if (GUILayout.Button(match.name))
    66.             {
    67.                 networkMatch.JoinMatch(match.networkId, "", OnMatchJoined);
    68.             }
    69.         }
    70.     }
    71.    
    72.     public void OnMatchCreate(CreateMatchResponse matchResponse)
    73.     {
    74.         if (matchResponse.success)
    75.         {
    76.             Debug.Log("Create match succeeded");
    77.             matchCreated = true;
    78.             Utility.SetAccessTokenForNetwork(matchResponse.networkId, new NetworkAccessToken(matchResponse.accessTokenString));
    79.             NetworkServer.RegisterHandler(MsgType.Connect, SOnConnected);
    80.             NetworkServer.RegisterHandler(1002, SOn1002);
    81.             NetworkServer.Listen(new MatchInfo(matchResponse), 9000);
    82.         }
    83.         else
    84.         {
    85.             Debug.LogError ("Create match failed");
    86.         }
    87.     }
    88.    
    89.     public void OnMatchList(ListMatchResponse matchListResponse)
    90.     {
    91.         if (matchListResponse.success && matchListResponse.matches != null)
    92.         {
    93.             networkMatch.JoinMatch(matchListResponse.matches[0].networkId, "", OnMatchJoined);
    94.         }
    95.     }
    96.    
    97.     public void OnMatchJoined(JoinMatchResponse matchJoin)
    98.     {
    99.         if (matchJoin.success)
    100.         {
    101.             Debug.Log("Join match succeeded");
    102.             if (matchCreated)
    103.             {
    104.                 Debug.LogWarning("Match already set up, aborting...");
    105.                 return;
    106.             }
    107.             Utility.SetAccessTokenForNetwork(matchJoin.networkId, new NetworkAccessToken(matchJoin.accessTokenString));
    108.             myClient = new NetworkClient();
    109.             myClient.RegisterHandler(MsgType.Connect, COnConnected);
    110.             myClient.RegisterHandler(1001, COn1001);
    111.             myClient.Connect(new MatchInfo(matchJoin));
    112.         }
    113.         else
    114.         {
    115.             Debug.LogError("Join match failed");
    116.         }
    117.     }
    118.    
    119.     public void SOnConnected(NetworkMessage msg)
    120.     {
    121.         Debug.Log("S:Connected!");
    122.         NetworkServer.SetClientReady (msg.conn);
    123.         var m = new Message ();
    124.         m.s = 1001;
    125.         NetworkServer.SendToClient (msg.conn.connectionId, 1001, m);
    126.         label = "server";
    127.     }
    128.    
    129.     public void SOn1002(NetworkMessage msg)
    130.     {
    131.         Debug.Log("S:1002!");
    132.         var m = new Message ();
    133.         m.s = 1001;
    134.         NetworkServer.SendToClient (msg.conn.connectionId, 1001, m);
    135.         ++cnt;
    136.     }
    137.    
    138.     public void COnConnected(NetworkMessage msg)
    139.     {
    140.         Debug.Log("C:Connected!");
    141.         label = "client";
    142.     }
    143.  
    144.     public void COn1001(NetworkMessage msg)
    145.     {
    146.         ++cnt;
    147.         Debug.Log("C:1001!");
    148.         var m = new Message ();
    149.         m.s = 1002;
    150.         myClient.Send(1002, m);
    151.     }
    152. }
    sebeisdrache, sorry to interrupt your thread.
    LevonRavel, thank you for your response.
     
  20. LevonRavel

    LevonRavel

    Joined:
    Feb 26, 2014
    Posts:
    177
    I have not used Unity's MatchMaker, I would assume it would work in a same manner as the Crossnet example, Looking at your code seems like you might have already looked at a portion of the Crossnet manager. MatchMaker in that case might be different. Hopefully someone can get back to your posting as I am unable to help with this subject..

    Best Regards
    Levon Ravel.
     
  21. sebeisdrache

    sebeisdrache

    Joined:
    Jan 16, 2015
    Posts:
    34
    I thnik its the bandwith limit wich is not metioned in any documentation, that causes the timeout in my game.

    So someone know a was to use the Matchmaker without the relay server (just like the old networking system).

    edit:
    I tested this locally by joinig the server localy (Lan Direct connection to Localhost) and i got no timeouts. (I this Its really caused by the relay server)
     
    Last edited: Aug 30, 2015
  22. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    I keep getting Unet connection timeouts as well: "UNet Client Disconnect Error: Timeout". I doubt it's a bandwidth limit, because I have two objects in my scene that I let sit and do absolutely nothing, and the client still gets disconnected. I also don't make any scene changes or anything like that. This is using Unity's matchmaker system and the relay server.

    I have tested to make sure I'm not sending commands or remote calls in the Update functions, or anything that would potentially use up a large amount of bandwidth. My whole multiplayer system is using Unity's provided multiplayer scripts and objects (i.e. Network Manager, Network Transforms, etc...).

    All that I have seen on this subject are the posts that say that perhaps it's because people are hitting a bandwidth limit, but I don't see how that's possible in my project -- which is essentially a scene with two players and they only move and send data when commanded.
     
  23. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    Ok, so after doing even more research on this I came across this statement: "The server must recieve data from the client every 60 seconds or it will be disconnected. It is recommended that you send keep-alive packets every 25-55 seconds to prevent this from happening."

    Is this true? Can anyone confirm. So perhaps the problem is I'm not using ENOUGH bandwidth :rolleyes:
     
    Anisoropos likes this.
  24. Anisoropos

    Anisoropos

    Joined:
    Jul 30, 2012
    Posts:
    102
    For me this seems to have improved the stability (disconnecting every less than 5' -> disconnect at 15')

    Edit :: How-To send keep-alive packets.
    1. Create a [Cmd] function in any script that will always be active on the client side
    2. Call it from the client every X seconds (using a coroutine)
     
    Last edited: Apr 12, 2017
  25. Laszlo-Apro

    Laszlo-Apro

    Joined:
    Mar 29, 2016
    Posts:
    1
    @Anisoropos, could you please provide an example of how you send a keep-alive message to the server?
     
    Last edited: Apr 12, 2017
  26. Anisoropos

    Anisoropos

    Joined:
    Jul 30, 2012
    Posts:
    102
    Sure, updated the post with a high-level overview of the keep-alive message.