# How do I stop “StartServer listen failed” when I start a new server after a previous server has been destroyed?

I am trying to allow my users to be able to host servers for my game. Hosting works great, until a user decides to stop their server, and then start a new one. The game does not allow this to happen, and calls a network error:

StartServer listen failed.

How do I get around this error?

Here is my current code for disabling the current server and starting a new one:

//disconnect client/server
NetworkManager.networkManager.Disconnect ();

//set the port
NetworkManager.networkManager.networkPort = port;
//start the server
NetworkManager.networkManager.StartServer ();
//set the map
ServerInfoManager.serverInfoManager.ChangeMap (map);


Here is NetworkManager.Disconnect():

public void Disconnect () {
if (isServer == true) {
StopServer ();
}

if (isClient == true) {
StopClient ();
}
}


The isServer, isClient, args[], and port variables have been set before these code sections.

• This could be because port is set to a value that's in use or invalid. If it's set to the same value as before, then the previous instance is still using it. Try changing it to a different value (e.g. port+1) for debugging purposes. If the error goes away, you know that's the problem. – Peter Mar 23 '17 at 23:04
• The port is the same as before but I thought that would be fine because I am stopping the server by calling Disconnect(); The port needs to be able to be the same because the user should be able to launch a server with the same port as before if they want to restart the server or something. – Brady W Mar 23 '17 at 23:53
• I'm not saying changing ports is the solution. I'm saying changing ports will let you figure out the problem. If changing ports works, you know Disconnect doesn't close the port, at least not immediately.. – Peter Mar 24 '17 at 0:32
• @Peter I can confirm that changing the port does work, so Disconnect () must not close the port – Brady W Mar 24 '17 at 4:40
• Maybe you need shutdown instead docs.unity3d.com/ScriptReference/… – Peter Mar 24 '17 at 11:56