Since I didn’t receive any reply’s in multiplayer forum…
So, I’m trying to create a basic master server with multiple hosts using the code provided in Unity’s docs.
However, when I register multiple hosts only the first host shows up in the client program.
Here’s the code I’m using. Ignore the comments for MasterServer.RegisterHost.
void OnGUI()
{
if (GUILayout.Button ("Start Server"))
{
// Use NAT punchthrough if no public IP present
Network.InitializeServer(5, 25002, !Network.HavePublicAddress());
MasterServer.RegisterHost("SomeGame_ServerTypeUnique", "Test game0", "Testing Multiple Connections");
//Network.InitializeServer(4, 25003, !Network.HavePublicAddress());
MasterServer.RegisterHost("SomeGame_ServerTypeUnique", "Test game1", "Testing Multiple Connections");
//Network.InitializeServer(4, 25004, !Network.HavePublicAddress());
MasterServer.RegisterHost("SomeGame_ServerTypeUnique", "Test game2", "Query: Do we need to initialize multipleservers?");
//Network.InitializeServer(4, 25005, !Network.HavePublicAddress());
MasterServer.RegisterHost("SomeGame_ServerTypeUnique", "Test game3", "If so then I need to try it at some point");
//Network.InitializeServer(4, 25006, !Network.HavePublicAddress());
MasterServer.RegisterHost("SomeGame_ServerTypeUnique", "Test game4", "Wonder how many hosts one can register on a single computer?");
}
if (GUILayout.Button ("Exit"))
Application.Quit();
}
Here’s the Client side if I messed up something there.
void OnGUI()
{
HostData[] data = MasterServer.PollHostList();
// Go through all the hosts in the host list
foreach(HostData element in data)
{
GUILayout.BeginHorizontal();
var name = element.gameName + " " + element.connectedPlayers + " / " + element.playerLimit;
GUILayout.Label(name);
GUILayout.Space(5);
string hostInfo;
hostInfo = "[";
foreach(string host in element.ip)
hostInfo = hostInfo + host + ":" + element.port + " ";
hostInfo = hostInfo + "]";
GUILayout.Label(hostInfo);
GUILayout.Space(5);
GUILayout.Label(element.comment);
GUILayout.Space(5);
GUILayout.FlexibleSpace();
if (GUILayout.Button("Connect"))
{
// Connect to HostData struct, internally the correct method is used (GUID when using NAT).
Network.Connect(element);
}
GUILayout.EndHorizontal();
}
if (GUILayout.Button ("Exit"))
Application.Quit();
}
Only Test Game0 shows up on the client side and according to the hostlist the size is 1 so I’m not sure why the others aren’t registering.