Everything builds fine in Visual Studio 2010. I run the Master Server and Facilitator on my computer (local host) no problem. My Unity project has references to the IP addresses and ports before I even try to connect to it.
When I run my Unity game and connect the Master Server says it connects. Then I RegisterHost() and but I get this error when I try to RegisterHost() and then (in the same block of code) I check the RequestHostList() like so.
MasterServer.RegisterHost(“ZOnlineTest”, “Test game 001”, “Test game for ZOnline”);
MasterServer.RequestHostList(“ZOnlineTest”);
if (MasterServer.PollHostList().Length != 0)
{
HostData[ ] data = MasterServer.PollHostList();
for (int i = 0; i < data.Length; i++)
{
Debug.Log("Game name: " + data*.gameName);*
}*
MasterServer.ClearHostList();* } MasterServer.UnregisterHost(); However, it never goes into the IF statement “if (MasterServer.PollHostList().Length != 0)” so I never can see my registered game. When it gets to the UnregisterHost() I get this error. -ERROR- No table name defined, during query/removal. -ERROR- Malformed packet from 127.0.0.1:25002, packet size 138 bits. -INFO- Failed to remove row for 127.0.0.1:25002 because table lookup failed Does anyone have any idea why I cannot RequestHostList() on my local machine? Or why I am getting the errors? Any ideas would be much appreciated. Thanks! Kris
Try not unregistering host. See if that helps. The host is unregistered once the game is quit anyways. Also, maybe try waiting a second or two after you register a host before requesting a list.
@Killer1390: I tried your suggestion but it still did not work.
@EVERYONE ELSE:
OK, I’ve simplified everything into a tiny little script that has four buttons. I have included the MasterServer.exe (Windows) as well in my project so everything is here for anyone to try (especially Unity Tech). Here is the link below (use either one, I have two just in case one doesn’t work).
Button 1: “Register Host” - Calls the RegisterHost() method.
Button 2: “Request Host List” - Calls the RequestHostList() method.
Button 3: “Poll Host List” - Calls PollHostList() and logs if successful or fail (check the Console).
Button 4: “Request Poll Host List (This FAILS!)” - Does the same as button 2 and 3. Note this will fail.
So if you click button 1, then 2, then 3 you will successfully get the registered game.
If you click button 1 and then button 4 it will fail to get the registered game.
My analysis is that when I press button 1 and then 4 Unity does not actually send the RequestHostList until AFTER control is given back to Unity (it has left the “TestMasterServerHostList.cs” file) but at this point it is too late and it will fail to get the list when PollHostList is called. The PollHostList has already asked for any games but the RequestHostList has not gone out yet (it does when the script has completed and control is given back to Unity but this is too late).
So it looks like the RequestHostList will not actually be sent to the Master Server until Unity has control back from the C# script.
Run the app, click the buttons and carefully watch the output from the Master Server and the Console.
My question: Is this a bug or is it by design?
If it is a bug can someone at Unity Tech please fix it?
I am running the Master Server on my computer (Windows 7 Pro) as well as the client on my computer and I have all the ports open on my firewall that are defined in the ResetIP() method in the C# file.
Hi again, long time no post. Anyways, I was able to get the code working correctly. Off the top of my head I can’t remember what the correct answer is but I can crack open the WORKING code and post it for your reference. Just let me know if you want me to. Cheers! - Kris
@Tourist, yes I did crack open the code and the fix is in there (somewhere). If I remember correctly you have to give control back to Unity after calling RequestHostList() method. Basically, try waiting a few second in the Update() then call PollHostList() and you may need to return control back to Unity again for it to process the results. Kind of a pain but I believe this is how I solved it.
However, I’ve switched over to a third party library called TNet, which is WAY easier to implement and more powerful. For example, did you know that the built in Unity networking only allows 32 channels open at one time. Yes, so you can only host a maximum of 32 games at once. That’s a HUGE limitation if you plan on actually creating a commercial game and plan on having hundreds of games running at once. That limitation is a show-stopper for me so I’ve switched to TNet and highly recommend it! It’s not really expensive when you compare it to the other networking libraries out there and it has a much smaller memory footprint than most too (and full source code is included).
Let me know if you still want me to post the code for Unity networking. Cheers! - Kris
I think what I did was have two buttons (“Register” and another “Join”) on a UI. Then each button calls the associated function below. Note I was running a compiled Master Server and Facilitator executables on the same computer although you can skip the Facilitator if you pretend to have a public IP address (see code below) and just run the Master Server. Having the two pieces of code separated allows Unity to send off the RegisterHost to the Master Server and then allow it to “listen” for the response. Also, if this code does not work then I would suggest putting the “MasterServer.PollHostList()” block of code (below) into the Update() function as this will allow Unity the “breathing space” to “listen” for the response.
public void RegisterHostWithUnityMasterServer()
{
MasterServer.ipAddress = "127.0.0.1"; // Local host
MasterServer.port = 23466;
Network.natFacilitatorIP = "127.0.0.1"; // Local host
Network.natFacilitatorPort = 50005;
Network.connectionTesterIP = "127.0.0.1"; // Local host
Network.connectionTesterPort = 10737;
// Use NAT punchthrough if no public IP present
// Network.InitializeServer(32, 25002, !Network.HavePublicAddress());
Network.InitializeServer(32, 25002, false); // Pretend to have a public IP address.
MasterServer.RegisterHost("ZOnlineTest", "Test game 001", "Test game for ZOnline");
}
public static void JoinMasterServer()
{
MasterServer.RequestHostList("ZOnlineTest");
// If this doesn't work, try moving the entire IF statement below into an Update() function.
// If any hosts were received, display game name, the clear host list again.
if (MasterServer.PollHostList().Length != 0)
{
HostData[] data = MasterServer.PollHostList();
for (int i = 0; i < data.Length; i++)
{
Debug.Log("Game name: " + data[i].gameName);
}
MasterServer.ClearHostList();
}
}
the query that generates this error is when we try to unregister a server from the master server. In your code, there is no call of MasterServer.UnregisterHost().