PollHostList() only returning one HostData, regardless of how many registered hosts

Hello, I have been tring to wrap my mind around how to create a main menu where I can choose a server among a list currently registered hosts.

public void StartServer(string serverName) {
		Network.InitializeServer(32, 25000, !Network.HavePublicAddress());
		MasterServer.RegisterHost(gameName, serverName, "Test!");

First I run multiple instances of the game, each starting a server with this method and a chosen servername.

public void RefreshHostList() {

		refreshing = true;

	void Update() {
		if (refreshing) {
			if (MasterServer.PollHostList().Length != 0) {
				refreshing = false;
				hostData = MasterServer.PollHostList();

				Debug.Log (hostData.Length);

I then call the RefreshHostList() method on the instance that wants to see the ongoing servers, however, regardless of how many instances of the game are run and creating a server, the debug message will always tell me the hostdata only contains 1 element.

Been trying for hours, maybe there are something fundamentally wrong with my idea of the masterserver…Anyways, any help is very much appreciated!

Your problem is the receiving of the hosts is asynchronous. Currently you stop receiving once you got at least one host. You have to “poll” the list for a longer period. Some even clear the list after each poll and add the host to a seperate list, however i would recommend to just wait for a certain amount of time (2-3 sec) and then stop “receiving” / “polling”.

ps: I had to figure that out myself the hard way :smiley:

As we just figured out, down in the comments, the actual problem was that only one server was running due to the same port was used for all servers. So InitializeServer for every additional server actually failed but in a build you don’t notice that unless you check the return value of InitializeServer. In the case that the port is already in use it will probably return NetworkConnectionError.CreateSocketOrThreadFailure, however every value that isn’t NoError is bad :wink: