I have a problem with this function,
When i close client and get this code that will crash:
void OnDisconnectedFromServer (NetworkDisconnection info) {
if(Network.isServer){
Network.Disconnect();
MasterServer.UnregisterHost();
Debug.Log("Local Server Close Connection");
}
}
i have try to put a button where i click and disconnect but same i get freeze client and crash.
that is a unity problem and i need to ask them? or i wrong somwthing?
2 Answers
2
It doesn’t make much sense to call Network.Disconnect in OnDisconnectedFromServer since this callback is called when you have been disconnected. Additionally the server can’t really be disconnected from the server since he is the server. However it might be possible that the callback is called on the server as well and your Network.Disconnect call send Unity in an endless recursion.
I replicated the crash myself.
As Bunny83 suggested, if you put:
void OnDisconnectedFromServer()
{
Network.Disconnect(); //NOOOooooo!!
}
It seems to put Unity into an infinite loop (stack overflow).
Almost certainly Network.Disconnect() calls OnDisconnectedFromServer() internally.
Ah oki thanks for explain :-) now i have understand, then i don't need to disconnect server, but if i want close server connection with a button how i can do?
– AnimaLSinaIt's perfectly fine to use Network.Disconnect to close a server. The example in the docs actually show how to close a server.
– Bunny83I get frreze of client if i use that in a button gui, server don't get disconnect but block everything and then crash, in webplayer and editor too. What is the problem then? If(gui.button(...)){ network.disconnect(); } Push and freeze like a recursive operation and webplayer get block and crash, don't take care about example i have write it with a tablet, just sense of code. If i can use that in server too, then i think that is a unity problem or just me get that error?
– AnimaLSinaWell, I've used that myself a couple of times, so there's no problem with that. Are you sure you don't call it in OnDisconnectedFromServer? Have you checked the [log files?][1] [1]: http://docs.unity3d.com/Documentation/Manual/LogFiles.html
– Bunny83Oki my fault... i have understand my error, i have forgot Network.Disconnect() in OnDisconnectFromServer function and when i pushed button Stop Server on function OnGUI if(GUILayout.Button("Stop Server")){ MasterServer.UnregisterHost(); Network.Disconnect(); } The function OnDisconnectFromServer started when the server went down then the second function Network.Disconnect stop everything :// Anyway thanks for all now work all ;D
– AnimaLSina