NetworkServer dosen't realese port when i close it
Hello, i have a problem related with the port of the server using UNET. The first time i start the server its just work fine, but when i close the server using NetworkServer.Shutdown the server is closed but when i try to reopen a new one on the same port using NetworkServer.Listen it retrive an error of port already in use.
There is a way to realease the port when i close the server?
Answer by alankemp · Apr 24, 2017 at 05:50 PM
Are you trying to close it and reopen it in one frame?
I've found that a lot of the network close/shutdown functions take a few frames to complete.
Try using a coroutine, call close, wait for it to actually close, then reopen it.
Answer by Pescu · Apr 24, 2017 at 06:09 PM
No, i don't try to reopen in the same frame but after some time as minutes, but without close the game. In fact if i reopen the game is everyting working.
Edit: I notice that this happens only when i start a match with objects spawn and client connected. When i start the server, and i immediately closed it without start a match i can reopen the server without errors.
But i still dont understand where is the problem. I close the server like this. Is every this okey?
Debug.Log("ShutdownCustomServer");
ClientCustomNetwork.Singleton.ShutdownLocalClient();
NetworkServer.ClearHandlers();
NetworkServer.ClearLocalObjects();
NetworkServer.ClearSpawners();
NetworkServer.DisconnectAll();
NetworkServer.Shutdown();
NetworkMasterClient.singleton.UnregisterHost(); // used to unregister the server on the masterserver.
Your answer
Follow this Question
Related Questions
Socket: set reusable port failed, error: Protocol not available(92), 0 Answers
Remote clients can no longer connect with new modem / router 0 Answers
How to pass argument(port) when starting a game built with Unity 0 Answers
Networking LLAPI and Port Forwarding 0 Answers
UNET NetworkTransport.AddHost - Check if port is already open 1 Answer