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

NetworkManager: Maximum hosts cannot exceed {16}

Discussion in 'Multiplayer' started by redduck100, Sep 9, 2016.

  1. redduck100

    redduck100

    Joined:
    Sep 10, 2014
    Posts:
    2
    maximum hosts cannot exceed {16}
    UnityEngine.Networking.NetworkManager:StartClient()
    s_NetworkManager:JoinGame() (at Assets/Scripts/Custom_Network/s_NetworkManager.cs:54)
    UnityEngine.EventSystems.EventSystem:Update()

    Unity Version : 5.4.0b23

    I'm using a custom network manager:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Networking;
    3. using UnityEngine.UI;
    4. using System.Collections;
    5. using System;
    6.  
    7. public class s_NetworkManager: NetworkManager {
    8.  
    9.  
    10.     public s_StatusInfo status;
    11.  
    12.     /// <summary>
    13.     /// Listener for the Start button.
    14.     /// </summary>
    15.     public void StartGame()
    16.     {
    17.         NetworkManager.singleton.StopHost();
    18.         NetworkManager.singleton.networkPort = 7777;
    19.         NetworkManager.singleton.StartHost();
    20.     }
    21.  
    22.  
    23.     /// <summary>
    24.     /// Listener for the Join button.
    25.     /// </summary>
    26.     public void JoinGame()
    27.     {
    28.         if (s_NetworkManagerUI.singleton.ipAdress)
    29.         {
    30.             if (s_NetworkManagerUI.singleton.ipAdress.text.Length > 0)
    31.             {
    32.                 string[] adress = s_NetworkManagerUI.singleton.ipAdress.text.Split(':');
    33.                 string ip = "";
    34.                 string port = "";
    35.  
    36.                 if (adress.Length >= 2)
    37.                 {
    38.                     ip = s_NetworkManagerUI.singleton.ipAdress.text.Split(':')[0];
    39.                     port = s_NetworkManagerUI.singleton.ipAdress.text.Split(':')[1];
    40.                 }
    41.  
    42.  
    43.  
    44.                 if (!string.IsNullOrEmpty(ip))
    45.                     NetworkManager.singleton.networkAddress = ip;
    46.                 else
    47.                     NetworkManager.singleton.networkAddress = "localhost";
    48.  
    49.                 if (!string.IsNullOrEmpty(port))
    50.                     NetworkManager.singleton.networkPort = int.Parse(port);
    51.                 else
    52.                     NetworkManager.singleton.networkPort = 7777;
    53.  
    54.                 NetworkManager.singleton.StartClient();
    55.             }
    56.             else
    57.             {
    58.                 Debug.LogError("Put a valid IP Adress!");
    59.             }
    60.         }
    61.     }
    62.  
    63.     /// <summary>
    64.     /// Listener for the Disconnect button.
    65.     /// </summary>
    66.     public void LeaveGame()
    67.     {
    68.         NetworkManager.singleton.StopHost();
    69.     }
    70.  
    71.     /// <summary>
    72.     /// Called when the local client connects to a server.
    73.     /// </summary>
    74.     /// <param name="conn"></param>
    75.     public override void OnClientConnect(NetworkConnection conn)
    76.     {
    77.         base.OnClientConnect(conn);
    78.         status.UpdateStatus("connected to a room...");
    79.  
    80.         s_NetworkManagerUI.singleton.SetUsername();
    81.         s_NetworkManagerUI.singleton.EnableConnectPanel(false);
    82.         s_NetworkManagerUI.singleton.EnableDisconnectPanel(true);
    83.         s_NetworkManagerUI.singleton.EnableGroupSelectPanel(true);
    84.     }
    85.  
    86.     /// <summary>
    87.     /// Called on the host when the server is stopped.
    88.     /// </summary>
    89.     public override void OnStopHost()
    90.     {
    91.         base.OnStopHost();
    92.         status.UpdateStatus("menu...");
    93.  
    94.         s_NetworkManagerUI.singleton.EnableChatPanel(false);
    95.         s_NetworkManagerUI.singleton.EnableDisconnectPanel(false);
    96.         s_NetworkManagerUI.singleton.EnableGroupSelectPanel(false);
    97.         s_NetworkManagerUI.singleton.EnableConnectPanel(true);
    98.     }
    99.  
    100.     /// <summary>
    101.     /// Called when the local client disconnects from a server.
    102.     /// </summary>
    103.     /// <param name="conn"></param>
    104.     public override void OnClientDisconnect(NetworkConnection conn)
    105.     {
    106.         base.OnClientDisconnect(conn);
    107.         status.UpdateStatus("menu...");
    108.  
    109.         s_NetworkManagerUI.singleton.EnableChatPanel(false);
    110.         s_NetworkManagerUI.singleton.EnableDisconnectPanel(false);
    111.         s_NetworkManagerUI.singleton.EnableGroupSelectPanel(false);
    112.         s_NetworkManagerUI.singleton.EnableConnectPanel(true);
    113.     }
    114. }
    115.  
    How to reproduce:
    1. Insert an ip to an offline or unreachable server.
    2. Press join 17 times.
    I've tried to remove the host manually and it doesn't work.
    I'm not sure if this is a bug or I'm doing something wrong.
     
  2. gintautass

    gintautass

    QA Minion Unity Technologies

    Joined:
    Oct 27, 2015
    Posts:
    46
    Did a quick test with 5.4.0p1 and did not get a repro.

    Could you download the latest version and see if it reproduces?
    If it does, please file a bug report and send me the case number.
     
  3. redduck100

    redduck100

    Joined:
    Sep 10, 2014
    Posts:
    2
    I just tried with the 5.5.0b2 version and I still get the error.
    Submitted a bug report and this is the case number : 830700
     
  4. Femidko

    Femidko

    Joined:
    Aug 4, 2013
    Posts:
    55
    I have the same problem. Connecting to the different combat servers after 17 times get the same error
     
  5. Femidko

    Femidko

    Joined:
    Aug 4, 2013
    Posts:
    55
    Bug more than a year! I'm in amazement.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Networking;
    3.  
    4. public class NetworkClientMy : NetworkClient
    5. {
    6.     public NetworkClientMy(string _host, int _port) {
    7.         Connect(_host, _port);
    8.     }
    9.  
    10.     public void ReConnect(string _host, int _port)
    11.     {
    12.         if(isConnected)
    13.         {
    14.             Disconnect();
    15. //                   NetworkTransport.RemoveHost(connection.hostId);
    16.         }
    17.    
    18.                Connect(_host, _port);
    19. //                  ReconnectToNewHost(_host, _port);
    20.     }
    21. }
    In 16th ReConnect error occurs: maximum hosts cannot exceed {16}. Can someone tell whether there is a solution how to bypass the error?
     
    Last edited: Oct 28, 2016
  6. tungchengvn

    tungchengvn

    Joined:
    Sep 30, 2014
    Posts:
    13
    I take a look on NetworkManager source code from https://bitbucket.org/Unity-Technologies/networking/src.

    They StopClient by Disconnect then Shutdown the old NetworkClient instance.

    Code (CSharp):
    1. if (client != null)
    2.             {
    3.                 // only shutdown this client, not ALL clients.
    4.                 client.Disconnect();
    5.                 client.Shutdown();
    6.                 client = null;
    7.             }
    I think we have to use new NetworkClient to reconnect. I create a Reconnect function in that way and I see no error occurs.

    Code (CSharp):
    1. public void Reconnect()
    2.         {
    3.             if (client != null) // if comment this block, old client will be used to call Connect again
    4.             {
    5.                 client.Disconnect();
    6.                 client.Shutdown();
    7.                 client = null;
    8.             }
    9.  
    10.             if (client == null)
    11.             {
    12.                 NetworkCRC.scriptCRCCheck = false;
    13.  
    14.                 client = new NetworkClient();
    15.                 client.Configure(connConfig, 800);
    16.  
    17.                 client.RegisterHandler(MsgType.Connect, OnConnect);
    18.                 client.RegisterHandler(MsgType.Disconnect, OnDisConnect);
    19.                 client.RegisterHandler(MsgType.Error, OnError);
    20.                 // ... more handler callback
    21.  
    22.                 client.Connect(serverIP, serverPort); // test ok with 20 times Reconnect
    23.             }
    24.             else
    25.             {
    26.                 // will have error after 16 times Reconnect
    27.                 client.Connect(serverIP, serverPort);
    28.             }
    29.         }
     
    Last edited: Oct 29, 2016
  7. diego-vieira

    diego-vieira

    Joined:
    Mar 27, 2015
    Posts:
    31
    tungchengvn, where can I place this reconnect function, since my scene changes when player disconnects?

    Thanks.
     
  8. tungchengvn

    tungchengvn

    Joined:
    Sep 30, 2014
    Posts:
    13
    Use it with your NetworkClient in a Singleton or DontDestroyOnLoad GameObject. Make sure that there only one network instance at a time is the rule.