I'm using the Network Manager. When I start the server (or host), stop it, and start it again, I get the error message: Code (CSharp): 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 http://pastebin.com/qRuRJZcb
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.
You definitely mean either: Code (CSharp): this.GetComponent«NetworkManager»().StopServer(); NetworkServer.Reset(); or: Code (CSharp): 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...
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. Code (CSharp): 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 } } }
NetworkTransport is a static class with static member functions so you can just call it anywhere you see fit.
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. Code (CSharp): 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 } } }
Hi I'm currently using 5.1.1f1 and I also get "StartServer listen failed." after closing a host and trying to start a new one. It does not matter if I use the NetworkManager HUD or do it myself inside C#. I'm not able to open a host after it got closed. The workaround of starting a client and after that starting the host works 1 time. After that back to "StartServer listen failed". Looks like the bug is still not fixed ;D EDIT: Just as an info, that's the code which get's used in the GUI (port is set somewhere else, but this is working) Code (CSharp): public void HostGame() { NetworkManager.singleton.StartHost(); } public void JoinGame(InputField input) { NetworkManager.singleton.networkAddress = input.text; NetworkManager.singleton.StartClient(); } public void LeaveMatch() { NetworkManager.singleton.StopHost(); NetworkManager.singleton.StopClient(); }
I tried this code on 5.1.1p4 and still getting this error; StartServer listen failed. UnityEngine.Networking.NetworkManager:StartHost() NetworkManagerCustom:StartupHost() (at Assets/Scripts/NetworkManager/NetworkManagerCustom.cs:11) UnityEngine.EventSystems.EventSystem:Update()
Maybe have a look at my video. Perhaps there's something in how I have things setup or something that I've said in it that might be useful to you.
I have already watched the video. Thanks for the response and also for the videos. They're very helpful. i guess i will check the other template projects to see where im doing wrong.
is there anything else in the console log or editor log? is this being called twice and failing the second time?
Also on 5.1.1P4 and getting this error. "StartServer listed failed" is only appearing once in the console. To reproduce, just host, leave the game and try to host another. But that's only if I stop the client without stopping the host
This happens to me when hosting the game for the first time. I did some tests. My network manager screen loads after my main (Account verification screen). When i discard the main screen and build from directly the network manager screen, there is no errors except the errors about my account system. Here is the code im using to host a new game which i take from GTGD's video tutorial. using UnityEngine; using System.Collections; using UnityEngine.Networking; using UnityEngine.UI; public class NetworkManagerCustom : NetworkManager { public void StartupHost() { SetPort (); NetworkManager.singleton.StartHost (); } public void JoinGame() { SetIPAdress (); SetPort (); NetworkManager.singleton.StartClient (); } void SetIPAdress() { string ipAdress = GameObject.Find ("InputFieldIPAdress").transform.FindChild ("Text").GetComponent<Text> ().text; NetworkManager.singleton.networkAddress = ipAdress; } void SetPort() { NetworkManager.singleton.networkPort = 7777; } void OnLevelWasLoaded(int level) { print ("MY CURRENT LEVEL : " + level); if(level == 1) //Network manager screen ("Zero" is the account login scene) { SetupMenuSceneButtons(); } else if(level == 2) // Ingame Scene { SetupOtherSceneButtons(); } } void SetupMenuSceneButtons() { 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); } void SetupOtherSceneButtons() { GameObject.Find ("ButtonDisconnect").GetComponent<Button> ().onClick.RemoveAllListeners (); GameObject.Find ("ButtonDisconnect").GetComponent<Button> ().onClick.AddListener (NetworkManager.singleton.StopHost); } }
This is probably a silly question, but have you checked that there isn't a NetworkManager in your main scene as well when you aren't running the game?
I'm sure that i have only one network manager which is seperated from other scenes. I had a cloud build also. I think no one is using that version of the game currently. I'm the only one who can reach that project.
mine works now but not with your same code GTGD. I had to modify it and add an extra script but it works. .
https://drive.google.com/file/d/0B9b5rsaXNB-KWmNpSHRXTUp4WjA/view?usp=sharing I made this with 5.1.1p4 if anyone's interested in seeing a working setup.
Hello. Thanks for your tutorial GTGD. I follow exactely what you did, so I have the same code as you paste here. But I have the same problem as everyone: - I click on "start host', it work. - I deconnect. - I click on "start host" again : I have "'StartServer listen failed". Anytime I click. The strange thing is when i write "localhost" in the inputfield, I click on 'joingame', it doesn't work, but then I click on start host and... it work again ! but... only once. If I redo the manipulation, it is definitely not working.
Seems fixed after upgrading to Unity 5.1.2f1 - I was having same issue as Koesys when following GTGD's tutorial with Unity 5.1.1f1 on OSX. There is a new warning though that seems to reveal what was happening: Multiple NetworkManagers detected in the scene. Only one NetworkManager can exist at a time. The duplicate NetworkManager will not be used. UnityEngine.Networking.NetworkManager:Awake() I think the problem was the Network Manager would be created in the Menu scene, then because 'Dont Destroy on Load' is enabled it would stay around when switching to Main scene, but when you disconnect and go back to 'Menu' scene it was trying to create a new Network Manager, when you already have one. Not sure best fix, but guessing writing a script to create the network manager in the Menu scene only if one isn't already running. Anyone please feel free to suggest a better approach.
Hi, i have the same warning Multiple NetworkManagers detected in the scene. Only one NetworkManager can exist at a time. The duplicate NetworkManager will not be used. UnityEngine.Networking.NetworkManager:Awake() Bioert tell me : Try not to use the NetworkManager as a "classic" singlenton, instead create a separate GameObject Game Manager and make it a singlenton. What I found is that you need to establish each relative references, variables, UI, each time you Enter the game for the first time, load the online scene and go back to the offline scene. Try using OnlevelLoad to "Re-establish" variables and references. me: I dont have time to test it actually but maybe thats can help you! Edit: i see a new version 5.1.3 im gonna download it , maybe the bug is fixed,
this is just a warning.. if it occurs when returning to the staring scene it can be ignored. it is to prevent attempts to have multiple active NetworkManager instances at the same time.
I've stumbled over this warning too. In my setup, the NetworkManager is part of the menu scene (a scene object). The Don't destroy on load flag is enabled so the NetworkManager is still there when I move to the actual InGame scene. After disconnecting and returning to the menu, the warning is displayed. My (maybe naive) solution is that I just destroy the current NetworkManager object when disconnecting so that the NetworkManager object in the menu scene replaces the old one and becomes the new single active NetworkManager. I just don't like the idea of potentially having 2 NetworkManagers active at the same time, even if one of them is not gonna be used (what does this actually mean? Is it destroyed?). I also feel uncertain because the warning does not seem to specifiy which one of those duplicate NetworkManagers is not gonna be used. In the first place, I would have expected that the Don't destroy on load flags makes sure that there really is just 1 NetworkManager around, the initial one, without any warnings.
I'm stumped here - could really use some help! Does anyone know (using GTGD's script - thanks), how to hold off on launching the game until there are 2 players connected? Been trying for 4 days and can't figure it out. Whoever can help me out will be a legend! Thanks.
Override the player join event and increment a player count by 1. I've used this information both to start the game and also to assign spawn points. If you want an awkward way to do it, what I did was on spawning your player, increment a static player count in the player script. This will make an accurate count because other players get instantiated in your game when you join. So if you join second you will get a count of 2. Just add a condition in your player start function for when the count is equal to 2, and send a command to the server to start the game It's awkward, but it works both in assigning IDs that are already attached to the player and initiating events based on a particular number of players joining
Thanks Tom - I appreciate your help! Can you give an example of how I override the player join event (sorry - probably really simple!)? Is this done in my custom lobby scene or in the player script (in the game scene)? My preference would be to have the players wait in my custom lobby scene and when both are connected, the game launches... Basically, what I would like to have happen is: 1. The screen has 2 options (HOST GAME and JOIN GAME) - local multiplayer only at this stage 2. Player1 clicks HOST GAME on his/her device and is presented with 'Waiting for other player....' (There is also a cancel button if he/she wants to abort.) 3. Player2 clicks JOIN GAME on his/her device and when the system detects both players are connected it launches the game. My game doesn't have characters as such, as it involves both players taking turns at controlling the same object in turn. Basically, Player1 has control of the object and moves it in order to avoid an incoming obstacle. As soon as it has passed, Player2 has control and has to avoid the next obstacle. This goes on until 1 of the players gets hit by an obstacle, which then shows the accumulated score (eg: 3 : 1) and the players can choose to rematch or exit. Does this mean I don't need to spawn a player when I start the game, or do I still need one (invisible perhaps) so it can hold the script which communicates the players commands with the server? Any further assistance you can offer would be awesome - thanks!
http://docs.unity3d.com/ScriptReference/Networking.NetworkManager.html Scroll down to public functions. If you override OnServerConnect you can keep track of a player count for joining players and launch some sort of event when it happens. You need to have a class that extends the network manager class and then simply type override and autocomplete will handle the rest. You'll get the function stub + the call to the original function (super call). You can add your player counter somewhere in there.