- Home /
Master Server don't answer. OnMasterServerEvent never triggered.
Hi, I'm following this tutorial: http://www.paladinstudios.com/2013/07/10/how-to-create-an-online-multiplayer-game-with-unity/ and I never receive a host list.
I activated network debugger and the message I receive when I register the host is "Sent host registration to master server, registering a NAT assisted game as "RoomName", 1, 5, not password protected, "test"" But nothing in return.
And OnMasterServerEvent is never called. If I try to receive a hostlist the problem is exactly the same one, OnMasterServerEvent is never called and the list of host always empty.
What Can I do? :/ The connection seems fine I receive the messages:
"Connected to facilitator at 67.225.180.24:50005" and
"Connected to master server at 67.225.180.24:23466".
My code is:
public class NetworkManager : MonoBehaviour {
private const string typeName = "UniqueGameName";
private const string gameName = "RoomName";
private HostData[] hostList;
private void StartServer()
{
Network.InitializeServer(4, 25000, !Network.HavePublicAddress());
MasterServer.RegisterHost(typeName, gameName, "test");
}
void OnServerInitialized()
{
Debug.Log("Server Initializied");
}
void OnGUI()
{
if (!Network.isClient && !Network.isServer)
{
if (GUI.Button(new Rect(100, 100, 250, 100), "Start Server"))
StartServer();
if (GUI.Button(new Rect(100, 250, 250, 100), "Refresh Hosts"))
RefreshHostList();
if (hostList != null)
{
for (int i = 0; i < hostList.Length; i++)
{
if (GUI.Button(new Rect(400, 100 + (110 * i), 300, 100), hostList[i].gameName))
JoinServer(hostList[i]);
}
}
}
}
private void RefreshHostList()
{
MasterServer.ClearHostList();
MasterServer.RequestHostList(typeName);
Debug.Log("Waiting");
}
void OnMasterServerEvent(MasterServerEvent msEvent)
{
Debug.Log("MasterServerReached");
if (msEvent == MasterServerEvent.HostListReceived)
hostList = MasterServer.PollHostList();
}
private void JoinServer(HostData hostData)
{
Network.Connect(hostData);
}
void OnConnectedToServer()
{
Debug.Log("Server Joined");
}
}
Could be wrong here, but it seems to me that the way you coded the buttons to be displayed using
if (!Network.isClient && !Network.isServer)
You're showing the buttons when you're not a client AND not a server.
You could build your game and run it once via the build and once in your editor, this way you should be able to be the client once and see the server you launched in the other version running...
Hope this helps.
Thanks you for your answer.
if (!Network.isClient && !Network.isServer)
It's not a mistake, because you are not client until you join a host. When you join a host or you are a server, buttons aren't painted anymore.
But finally I solved the problem. I just executed today unity (after spending yesterday 2 hours on this problem) and It just works. I received a message in order to convert spaces in the script file to another format and It works fine now.
So next time, I'll better try to restart unity in the first instance.