StartServer listen failed.

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’m on OSX with Unity 5.1.1

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.

Here’s the code I was using ConnectionManager.cs - Pastebin.com

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.

Submitted a bug: 705831

I am getting the same error.

This bug seems to have appeared in 5.1.0f3 and is still present in 5.1.1p1.

I believe this is a regression as this bug was not present in 5.1.0f2 and I originally had this functionality working.

@any_user Did you file the bug? The issue tracker has no issue for 705831.

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.

This bug has been already fixed in patch 5.1.1p2

Confirmed, also having this issue on 5.1.1p1.

When will this release? Start of next week?

I think so

right now You can fix this bug manually call Receiv() method before You will add new host

You definitely mean either:

this.GetComponent«NetworkManager»().StopServer();
NetworkServer.Reset();

or:

this.GetComponent<NetworkManager>().StopHost();
NetworkServer.Reset();

And not “receiv”!

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…

Thanks for the response @aabramychev

I can confirm that this is fixed in 5.1.1p2.

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
        }
    }
}

“when i do as i do, i haven’t” :wink:

Could you attach your project here? I will take a look

Where can I access the NetworkTransport object from NetworkManager?

NetworkTransport is a static class with static member functions so you can just call it anywhere you see fit.

1 Like

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.

Here’s my corrected code that works and here’s a download for the project folder for anyone interested.

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
using UnityEngine.UI;

public class NetworkManager_Custom : NetworkManager {

    public void StartupHost()
    {
        SetPort();
        NetworkManager.singleton.StartHost();
    }

    public void JoinGame()
    {
        SetIPAddress();
        SetPort();
        NetworkManager.singleton.StartClient();
    }

    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.RemoveAllListeners();
            GameObject.Find("ButtonStartHost").GetComponent<Button>().onClick.AddListener(StartupHost);

            GameObject.Find("ButtonJoinGame").GetComponent<Button>().onClick.RemoveAllListeners();
            GameObject.Find("ButtonJoinGame").GetComponent<Button>().onClick.AddListener(JoinGame);
        }

        else
        {
            GameObject.Find("ButtonDisconnect").GetComponent<Button>().onClick.RemoveAllListeners();
            GameObject.Find("ButtonDisconnect").GetComponent<Button>().onClick.AddListener(NetworkManager.singleton.StopHost); //Unity method
        }
    }

}

Thanks :slight_smile: Could you close this bug as resolved? :slight_smile: