Hey guys,
We are using stock standard Unity networking for a game targeting mobile devices. We are hosting our own MasterServer / Facilitator from a CentOS based VPS. Most of the time the network works just fine, however there are instances where ‘MasterServer.RegisterHost’ stops working entirely for a single device. This is usually after a rapid disconnect, i.e, pressing home button soon after connecting, but not always.
What I mean by RegisterHost seemingly stops working is, normally, with network logging turned to full, RegisterHost will output this:
“Attempting to connect to master server at 198.136.XX.XX:23466
UnityEngine.MasterServer:RegisterHost(String, String, String)”
However when the device is in the ‘broken’ state, RegisterHost will produce no output at all. The MasterServer itself will still happily connect other devices. The Facilitator will receive connections from the broken device, but until the application is restarted, ‘RegisterHost’ won’t try and reach the MasterServer. (On mobiles of course, this means force stopping the application, which isn’t feasible for users.)
Is there a way we can ‘restart’ Unity’s internal networking without restarting the App? Or is there something we are doing to cause these circumstances? Or even just find out whats going wrong without having access to the source code?
In short… Help!
(Note that restarting the MasterServer on our VPS has no effect to a devices connectiblility. If it can no longer connect, the ONLY solution we have found is restarting that device.)
I have submitted a bug report on this to Unity, however I’d like to update this thread as well in case anyone here has a faster response.
We have created a small sample scene that shows the problem we are having, you can reproduce it yourself quite easily following these steps:
The example scene contains 4 buttons. The bottom three are similar to how we have set up our networking. Create a server, followed by attempting to register, followed by disconnecting at a later time. This flow will normally work fine. The top button, creatively labeled ‘Break Networking’ demonstrates what happens when two functions, i.e. disconnect etc, get called rapidly. Once that button has been pressed, Register Host (As shown in the console output) will no longer function as required.
Here is an excerpt of the code from the “Break Networking” button, obviously we don’t use it like this in game, however this method produces the same result as what we occasionally experience.
// Breaks the build with an attempt to register and disconnect
if(GUI.Button(new Rect(fX, fY, fButtonWidth, fButtonHeight), "Break Networking"))
{
if(Network.peerType != NetworkPeerType.Server)
{
CreateServer();
}
MasterServer.RegisterHost("gameTypeName", "gameName");
Network.Disconnect();
MasterServer.UnregisterHost();
}
void CreateServer()
{
Network.InitializeServer(0, 25001, true);
}
And here is the test scene 1027691–38135–$NetworkSandbox.rar (143 KB)
Did this ever get addressed? We are experiencing this bug as well.
We’re using unity 3.5.6 - we will probably upgrade if this is fixed in another unity version.