- Home /
You may not be connected when initializing security layer.
Hello! I use my computer to test my builds. I make one build be the server and the editor to be the client. The build (server) disconnects and the editor disconnects with it. After that, I make a server with the editor and it says 'You may not be connected when initializing security layer.' It really bugs me. Is it because I'm using only one computer?
P.S.: I used the same IP and port for the two times I've created the server. I'm using Unity's built-in networking (Network.Connect(); and Network.InitializeSecurity(); and Network.InitializeServer();)
Answer by Bunny83 · Jan 06, 2014 at 03:16 AM
Are you sure that you call "Network.InitializeSecurity" before you call "Network.InitializeServer" or "Network.Connect"? Also are you sure that you're disconnected? You can check Network-peerType if you're Disconnected.
It says I'm not connected whenever I make a server so that isn't the problem... Yup I call it before... It happens when I (editor) connect to a server then the server EXITS out by clicking the X on the window. After that if I (editor) make a server, it does that.
I've tried debug logging. Before I create the server, I'm always disconnected. I also tried doing timers to wait after initializing security but that didn't work either. Yes, I call it before. Also, you don't put Network.InitializeSecurity before Network.Connect because you're not supposed to call it on the client.
I can also confirm this is happening. Running Build and Editor :
Build creates a server
Editor joins the server
Build closes the server with Network.Disconnect(150);
Editor console reports The server has disconnected from the client. $$anonymous$$ost likely the server has shut down.
Editor debug from OnDisconnectedFromServer is from when info == NetworkDisconnection.Disconnected
Editor debug from return to main menu function is from when Network.peerType == NetworkPeerType.Disconnected
Editor creates a server
Editor reports You may not be connected when initializing security layer.
I tried adding Network.Disconnect(150); to OnDisconnectedFromServer but that just crashed the editor.