- Home /
UNET Transport Layer "Host ID is out of bound {0}"
I am playing around with a multi-host solution using Unet's Transport Layer. I can add hosts fine but when I try to connect a client I get the following Error:
host id out of bound id {0} max id should be greater 0 and less than {0}
Here is my connection Code:
public void Start (){
Configure ();
Connect ();
}
public void Configure (){
NetworkTransport.Init ();
ConnectionConfig Config = new ConnectionConfig ();
Config.AddChannel (QosType.ReliableFragmented);
Topology = new HostTopology (Config, MaxConnections);
if (Server)
{
HostID = NetworkTransport.AddHost (Topology, ServerPort, ServerIP);
CreateHost ();
}
}
public int FindPort (){
if (OpenPorts.Count > 0){
int Port = OpenPorts [0];
OpenPorts.Remove (Port);
return Port;
}
return 0;
}
public void CreateHost (){
int Port = FindPort ();
Host Host = (Host)Factory.Script.Create ("Host", "Host", Hosts);
Host.HostID = NetworkTransport.AddHost (Topology, Port);
Host.Port = Port;
}
public void Connect (){
ConnectionID = NetworkTransport.Connect (0, ServerIP, ServerPort, 0, out Error);
}
When I connect a new Host I can see that it is a assigned a HostID. No matter which HostID I feed to the client connection I get the above error. Am I missing something?
Thanks, Sean
NOTE
For late 2018 I found one of the problems, recently introduced by Unity.
Note the aside in RED near the middle. That's the secret
"(Important aside. For late 2018 you must stop your client discovery above in OnClientConnect, directly after the call to the base. You actually can NOT do it in your discovery client.)"
Answer by Ahndrakhul · Nov 29, 2015 at 10:13 AM
I have just recently started trying to learn about NetworkTransport, so I could be totally wrong about this, but your problem might stem from:
if (Server)
{
HostID = NetworkTransport.AddHost (Topology, ServerPort, ServerIP);
CreateHost (40.7500f, 111.8833f, 50f);
}
As I understand it, even clients need to use NetworkTransport.AddHost. The "AddHost" name confused me at first, but it seems to be what is responsible for creating and registering sockets with NetworkTransport on both the server and the clients. Using "0" or any other hostId for the hostId parameter in:
public void Connect (){
ConnectionID = NetworkTransport.Connect (0, ServerIP, ServerPort, 0, out Error);
}
will fail because AddHost was never called on the client (as far as I can tell), and as a result, the client's NetworkTransport has no registered socket to use for the connection that corresponds with the "connectionId" you are giving it; in fact, it has no registered sockets at all.
you might want to add something like:
ConnectionConfig config = new ConnectionConfig();
reliableFragmentedChannel = config.AddChannel(QosType.ReliableFragmented);
HostTopology topology = new HostTopology(config, maxConnections);
clientSocket = NetworkTransport.AddHost(topology);
to an if (Client) part of your code somewhere and then use "clientSocket" as the hostId in the Connect method.
Hopefully I'm not misunderstanding everything. Good luck!
This was absolutely the answer. You have to call "AddHost" on even the clients. Thanks so much, I am up and running Sending all kinds of transmissions! :D
They should change the name of that call to "OpenSocket", that would get people up and running I think.
Thanks again, Sean
Answer by ShantuApps · Feb 11, 2018 at 03:48 PM
try
{
NetworkTransport.RemoveHost(1);
NetworkTransport.RemoveHost(2);
NetworkTransport.RemoveHost(3);
NetworkTransport.RemoveHost(4);
}
catch
{
// Do nothing
}
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Unity's LLAPI for Raspberry Pi Server? 0 Answers
Multiple Cars not working 1 Answer
How can I read data sent using the Transport API with python server 1 Answer
NetworkManager.OnServerDisconnect not being called 2 Answers