I’m using the Network Manager. When I start the server (or host), stop it, and start it again, I get the error message:
StartServer listen failed.
It works again when I restart the build or restart the game in the editor. Looks like the port of the first server (7777 in my case) is still in use after stopping the server. If I change it for the second start, it works.
Is there anything else I have to do to stop a server except calling NetworkManager.StopServer() ?
I had the same issue with the NetworkManagerHub after restarting the server as a host. I noticed the error could be avoided if you start a client, stop it, then go back to hosting. Could this be a bug? Perhaps it’s due to a method being overwritten.
It clearly seems to be a bug, it’s easy to reproduce it in an empty project without any custom scripts. In a scene with just a NetworkManager + NetworkManagerHUD, Start Server → Stop Server → Start Server shows the error.
I filed the bug, but no feedback except the automatic mail, don’t know why it doesn’t show up in the tracker. I can confirm the issue is still there in 5.1.1p1.
No, I meant NetworkTransport.Recieve() call after StopHost() or (better) before AddHost. But it is temporary solution, with the next patch this problem will be solved…
How do I make use of NetworkTransport.Receive()? I can see the parameters in the manual and that there are three event types but I don’t understand how to make use of this method.
I’m using 5.1.1p2 and I’m finding that this bug is still there if I don’t use the NetworkManagerHUD for starting and stopping a host. My custom network manager is very simple and doesn’t override any part of the default network manager. I just have some additional functions so that I can use my own UI. When I make a host game, then disconnect, and then try to host again I get the error the original poster mentioned.
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
using UnityEngine.UI;
public class NetworkManager_Custom : NetworkManager {
public void StartupHost()
{
SetPort();
StartHost(); //Unity method
}
public void JoinGame()
{
SetIPAddress();
SetPort();
StartClient(); //Unity method
}
void SetIPAddress()
{
string ipAddress = GameObject.Find("InputFieldIPAddress").transform.FindChild("Text").GetComponent<Text>().text;
networkAddress = ipAddress;
}
void SetPort()
{
networkPort = 4444;
}
void OnLevelWasLoaded (int level)
{
if(level == 0)
{
GameObject.Find("ButtonStartHost").GetComponent<Button>().onClick.AddListener(StartupHost);
GameObject.Find("ButtonJoinGame").GetComponent<Button>().onClick.AddListener(JoinGame);
}
else
{
GameObject.Find("ButtonDisconnect").GetComponent<Button>().onClick.AddListener(StopHost); //Unity method
}
}
}
Thanks, it was my mistake. I submitted a bug report Case 708281 and it turned out that my code for adding a listener to the button wasn’t correct and was calling the StartHost method more than once. I changed my code to remove listeners from the buttons first and I also realised that I needed to change how I called the StartHost, StartClient, and StopHost methods by first using NetworkManager.singleton.StartHost() for example.