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

why "host id out of bound id {-1}" when using LLAPI addhost

Discussion in 'Multiplayer' started by CyberTurboPlays, Nov 15, 2015.

  1. CyberTurboPlays

    CyberTurboPlays

    Joined:
    Nov 7, 2014
    Posts:
    65
    hi all, i am playing around with the LLAPI and follow the doc set up flow, when testing on local pc with only one instance of the game running, NetworkTrasport.AddHost and Connect, are all working.

    but if i start a game build, and let it NetworkTrasport.AddHost and Connect first, then i hit play in the editor (2 instance of the game on same local pc), it would give me "host id out of bound id" error.

    according to the doc, AddHost (create open socket) should be like create a new socket to be used in that instance of the game, but right now, its like AddHost is actually creating a new socket and binding it to a port at the same time, which is what the server socket should be doing, so when 2 instance of the game running (NetworkTrasport.AddHost and Connect call at start), its like starting 2 server side app and the 1st one got to bind the port and the later one will return error since that port has been binded, and i m guessing thats why i m getting "host id out of bound id" error, and have -1 in return when AddHost is called in the 2nd game instance.

    if that s the case, what should i use to create socket for client end? a socket not meant to bind any port, but to connect and send. i scroll through the NetworkTransport Script ref doc and cant really see anything that would be suitable for that.

    wel, i might be wrong on my guess about the AddHost call, can anyone tell where did i go wrong on this?
    I am calling the following 2 methods in the start of the game

    Code (CSharp):
    1.     void OpenSocket()
    2.     {
    3.         NetworkTransport.Init();
    4.         ConnectionConfig cConf = new ConnectionConfig();
    5.         _unreliableChannelId = cConf.AddChannel(QosType.Unreliable);
    6.         _reliableChannelId = cConf.AddChannel(QosType.Reliable);
    7.  
    8.         HostTopology hTopo = new HostTopology(cConf, MaxAllowConnections);
    9.  
    10.         _hostIdSocket = NetworkTransport.AddHost(hTopo, Port);//start a new socket and start accepting and listening, i guess
    11.     }
    12.  
    13.     void ConnectToSelfSocket()
    14.     {
    15.         Debug.Log("_selfConnectionId: " + _selfConnectionId);
    16.         byte error;
    17.         _selfConnectionId = NetworkTransport.Connect(_hostIdSocket, IpAddress, Port, 0, out error);
    18.         _isConnectedToSelfSock = error == 0;
    19.  
    20.         var res = "";
    21.         if (_isConnectedToSelfSock)
    22.         {
    23.             res = "Connect To Self Socket : Success = " + (NetworkError)error + " | _selfConnectionId: " + _selfConnectionId + " | _hostIdSocket: " + _hostIdSocket;
    24.             Debug.Log(res);
    25.             TextTopLeft.text = res;
    26.         }
    27.         else
    28.         {
    29.             res = "Connect To Self Socket : Error = " + (NetworkError)error + " | _selfConnectionId: " + _selfConnectionId + " | _hostIdSocket: " + _hostIdSocket;
    30.             Debug.Log(res);
    31.             TextTopLeft.text = res;
    32.         }
    33.     }
     
  2. CyberTurboPlays

    CyberTurboPlays

    Joined:
    Nov 7, 2014
    Posts:
    65
    i know what i did wrong now la, plz disregard this thread