Search Unity

ERROR maximum hosts cannot exceed {16}

Discussion in 'Multiplayer' started by ShizumaruRiya, Feb 8, 2017.

  1. ShizumaruRiya

    ShizumaruRiya

    Joined:
    Jan 5, 2014
    Posts:
    17
    Code (CSharp):
    1.         NetworkTransport.Init();
    2.         GlobalConfig gConfig = new GlobalConfig();
    3.         gConfig.MaxPacketSize = 500;
    4.         NetworkTransport.Init(gConfig);
    5.         ConnectionConfig config = new ConnectionConfig();
    6.         int myReiliableChannelId  = config.AddChannel(QosType.Reliable);
    7.         int myUnreliableChannelId = config.AddChannel(QosType.Unreliable);
    8.         int port = 8888;
    9.         for (int i = 0; i < 64; i++)
    10.         {
    11.             HostTopology topology = new HostTopology(config, 10);
    12.             int hostId = NetworkTransport.AddHost(topology, port); // maximum hosts cannot exceed {16}
    13.             port++;
    14.             Debug.Log("hostId: " + hostId);
    15.         }
    The hostId stopped at 15, then it return -1 and the for loop broken.
    This will cause an error: "maximum hosts cannot exceed {16}".
    Does it mean that UNET cannot open over 16 sockets?
     
    Last edited: Feb 8, 2017
  2. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    Yes, correct, we decided that nobody need more that 16 udp sockets open. Could you explain usecase when you need 64?
     
  3. ShizumaruRiya

    ShizumaruRiya

    Joined:
    Jan 5, 2014
    Posts:
    17
    Thank you for your reply.
    I'm using the RakNet(via DLL) for NAT-Punchthrough:
    http://www.raknet.net/raknet/manual/natpunchthrough.html

    And there is a library for Unity:
    https://github.com/noblewhale/NATPunchthroughClient

    When the Unity game start as a host and got a client connected.
    It will create a Unity NetworkServerSimple object and listen an UDP port for that client.
    Then the host reconnect to Facilitator and request a new GUID and UDP port for next client.
    It works fine if there are 15 clients connected to host.
    However, The NetworkServerSimple.Listen() contains the NetworkTransport.AddHost() function call.
    Due to the 16 sockets limit, I can't create a 32 vs 32 players game via that NAT-Punchthrough method with Unity Network LLAPI and HLAPI.
     
  4. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    Oops, it is definitely hack, but ok it is our fault as we haven't got has nat punch solution.... How many host do you need?
     
  5. ShizumaruRiya

    ShizumaruRiya

    Joined:
    Jan 5, 2014
    Posts:
    17
    In my case, I want to let user to host a 32 vs 32 multiplayer game with NAT-Punchthrough, even more players would be better.
    However, what's the reason for limiting the number of open sockets?
    If there is no strict limits, maybe developers could make some interesting things.
     
  6. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    with udp sockets u don't need to open a lot of socks as all communication you can do by using only one (your case is exception).
    Reasons:
    1. On mobile devices the function which handle multiple sockets is select() which has o(n) complexity.
    2. Each add socket will require resource pre-allocation, which can be big.
     
  7. ShizumaruRiya

    ShizumaruRiya

    Joined:
    Jan 5, 2014
    Posts:
    17
    Is it possiable let developer or user to decide the number of open sockets?
    eg. NetworkTransport.Init(HOST_COUNT) and default still 16.
    Maybe it is more flexible?
     
  8. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    In this case what will prevent you open 65545 sockets and open the bug that you don't have enough memory to handle all sockets? :)
     
    antoineracine likes this.
  9. ShizumaruRiya

    ShizumaruRiya

    Joined:
    Jan 5, 2014
    Posts:
    17
    So, Increase the limit and not called listen() or addhost() would also increase the memory usage?
    Well, About the suggestion above, That's just an option for adjust the max ability of open sockets, and there is still a bound of course.
    Open more sockets cost more resources for sure, but that might depend on developer or project.
    Maybe this is difficult to implement or not useful, never mind.
     
  10. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    I will change to 128 I guess it should be more that enough, hope with out implementation net punch, this problem will gone
     
    KevinHGS likes this.
  11. ShizumaruRiya

    ShizumaruRiya

    Joined:
    Jan 5, 2014
    Posts:
    17
    Thank you very much.
     
  12. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    done will be available in b11
     
  13. heiwa-games

    heiwa-games

    Joined:
    Apr 8, 2018
    Posts:
    8
    Hi,

    I am currently running 2018.2.18f1 Personal (64bit) and the limit still seems to be 16. What do I need to do, to get this up to 128?

    Cheers,
    Yasuko
     
  14. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574