Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by crodriguez · Oct 02, 2014 at 12:33 PM · networkingconnectionhostmaster server

Issue regarding PublicIPNoServerStarted. I am able to host a server, but nobody else can.

Hey there, I am working on the online mode of my project, and I am capable of hosting a game fine and my friend can join it. However, when he hosts a game, I cannot join his because he gets the ConnectionTesterStatus.PublicIPNoServerStarted message. This also happens with another friend when she tries to host a game. Also, he does get the message in the OnServerInitialized() function, so not quite sure what the problem is.

I'm not sure if this is a problem with the Master Server or if perhaps he would simply have to download the Master Server and Facilitator files that Unity provides. Any help on this problem would be appreciated, thanks.

Here is my code:

 public string playerName;
 
     string registeredGameName = "ProjectFlag_Server_Test";
 
     private bool useNAT = false;
 
     bool isRefreshing = false;
     float refreshRequestLength = 3.0f;
 
     private string titleMessage = "Project Flag Online Prototype";
     private string connectToIP = "127.0.0.1";
     private int connectionPort = 26500;
     private string ipAddress;
     private string port;
     public string serverName;
     public string serverNameForClient;
 
     private bool iWantToSetupAServer = false;
     private bool iWantToConnectToAServer = false;
 
     private int numberOfPlayers = 1;
 
     private ConnectionTesterStatus natCapable = ConnectionTesterStatus.Undetermined;
 
     private bool filterNATHosts = false;
 
     private string TestResults = "Detecting NAT capabilities...";
 
     HostData[] hostData;
 
     void Awake ()
     {
         natCapable = Network.TestConnection();
         if (Network.HavePublicAddress())
             Debug.Log("This machine has a public IP address");
         else
             Debug.Log("This machine has a private IP address");
 
         useNAT = !Network.HavePublicAddress();
     }
 
     // Use this for initialization
     void Start () 
     {    
         //Load the last used serverName from registry.
         //If the serverName is blank then use "Server"
         //as a default name.
         
         serverName = PlayerPrefs.GetString("serverName");
         
         if(serverName == "")
         {
             serverName = "Server";    
         }
         
         //Load the last used playerName from registry.
         //If the playerName is blank then use "Player"
         //as a default name.
         
         playerName = PlayerPrefs.GetString("playerName");
         
         if(playerName == "")
         {
             playerName = "Player";    
         }
     }
 
     // Update is called once per frame
     void Update () 
     {
         if(Input.GetKeyDown(KeyCode.Escape))
         {
             showDisconnectWindow = !showDisconnectWindow;
             showShutdownServerWindow = !showShutdownServerWindow;
         }
     }
 
     private void StartServer ()
     {
         Network.InitializeServer(numberOfPlayers, connectionPort, useNAT);
 
         MasterServer.RegisterHost(registeredGameName, serverName, "Test Implementation Of Server Code.");
     }
 
     void OnServerInitialized ()
     {
         Debug.Log("Server has been initialized");
 
         Debug.Log(MasterServer.port);
     }
 
     void OnMasterServerEvent (MasterServerEvent masterServerEvent)
     {
         if (masterServerEvent == MasterServerEvent.RegistrationSucceeded)
         {
             Debug.Log("Registration successful");
         }
     }
 
     public IEnumerator RefreshHostList ()
     {
         yield return new WaitForSeconds(1);
         Debug.Log("Refreshing...");
         MasterServer.RequestHostList(registeredGameName);
         float timeStarted = Time.time;
         float timeEnd = Time.time + refreshRequestLength;
 
         while (Time.time < timeEnd)
         {
             hostData = MasterServer.PollHostList();
             yield return new WaitForEndOfFrame();
         }
 
         if (hostData == null || hostData.Length == 0)
         {
             Debug.Log("No active servers at the moment.");
         }
         else
             Debug.Log(hostData.Length + " server has been found.");
     }
 
     void ConnectWindow(int windowID)
     {
         //Leave a gap from the header.
         
         GUILayout.Space(15);
         
         
         //When the player launches the game they have the option
         //to create a server or join a server. The variables
         //iWantToSetupAServer and iWantToConnectToAServer start as
         //false so the player is presented with two buttons
         //"Setup my server" and "Connect to a server". 
         
         if(iWantToSetupAServer == false && iWantToConnectToAServer == false)
         {
             if(GUILayout.Button("Create Game", GUILayout.Height(buttonHeight)))
             {
                 iWantToSetupAServer = true;    
             }
             
             GUILayout.Space(10);
             
             if(GUILayout.Button("Join Game", GUILayout.Height(buttonHeight)))
             {
                 iWantToConnectToAServer = true;
                 StartCoroutine(RefreshHostList());
             }
             
             GUILayout.Space(10);
             
             if(Application.isWebPlayer == false && Application.isEditor == false)
             {
                 if(GUILayout.Button("Exit Prototype", GUILayout.Height(buttonHeight)))
                 {
                     Application.Quit();    
                 }
             }
         }
 
         if(iWantToSetupAServer == true)
         {
             //The user can type a name for their server into
             //the textfield.
             
             GUILayout.Label("Enter a name for your game");
             serverName = GUILayout.TextField(serverName);
 
             GUILayout.Space(5);
 
             //The user can type in the Port number for their server
             //into textfield. We defined a default value above in the 
             //variables as 26500.
             
             GUILayout.Label("Server Port");
             connectionPort = int.Parse(GUILayout.TextField(connectionPort.ToString()));
 
             GUILayout.Space(5);
 
             GUILayout.Label("Player name");
             playerName = GUILayout.TextField(playerName);
             
             GUILayout.Space(10);
             
             if(GUILayout.Button("Create Match", GUILayout.Height(30)))
             {
                 //Create the server
                 StartServer();            
                 
                 //Save the serverName using PlayerPrefs.
                 PlayerPrefs.SetString("serverName", serverName);
                 PlayerPrefs.SetString("playerName", playerName);
                 
                 Network.Instantiate(GameManager, new Vector3(0, 0, 0), Quaternion.identity, 0);
                 Network.Instantiate(SpawnManager, new Vector3(0, 0, 0), Quaternion.identity, 0);
 
                 CommunicationWindow commScript = GameManager.GetComponent<CommunicationWindow>();
                 
                 Player1Health player1Script = GameManager.GetComponent<Player1Health>();
                 
                 commScript.playerName = playerName;
                 player1Script.playerName = playerName;
                 
                 iWantToSetupAServer = false;
             }
             
             if(GUILayout.Button("Go Back", GUILayout.Height(30)))
             {
                 iWantToSetupAServer = false;    
             }
         }
 
         if(iWantToConnectToAServer == true)
         {
             //The user can type their player name into the
             //textfield.
             GUILayout.Label("Enter your player name");
             playerName = GUILayout.TextField(playerName);
             
             GUILayout.Space(5);
             //The player can type the IP address for the server
             //that they want to connect to into the textfield.
             GUILayout.Label("Type in Server IP");
             connectToIP = GUILayout.TextField(connectToIP);
             
             GUILayout.Space(5);
 
             if (hostData != null)
             {
                 for (int i = 0; i < hostData.Length; i++)
                 {
                     if (hostData[i].connectedPlayers < hostData[i].playerLimit)
                     {
                         GUILayout.BeginHorizontal("box", GUILayout.Height(25));
 
                         if (GUILayout.Button("Join", GUILayout.Height(25), GUILayout.Width(50)))
                         {
                             //Ensure that the player can't join a game with an empty name
                             
                             if(playerName == "")
                             {
                                 playerName = "Player";    
                             }    
                             
                             //If the player has a name that isn't empty then attempt to join 
                             //the server.
                             
                             if(playerName != "")
                             {
                                 //Connect to a server with the IP address contained in
                                 //connectToIP and with the port number contained
                                 //in connectionPort.
 
                                 Network.Connect(hostData[i]);
                                 
                                 PlayerPrefs.SetString("playerName", playerName);
 
                                 Player2Health player2Script = GameManager.GetComponent<Player2Health>();
 
                                 player2Script.playerName = playerName;
                             }
                         }
                         GUILayout.Space(10);
                         GUILayout.Label(hostData[i].gameName, GUILayout.Height(25));
                         GUILayout.EndHorizontal();
                     }
                 }
             }    
 
             GUILayout.Space(5);
             
             if(GUILayout.Button("Refresh List", GUILayout.Width(100), GUILayout.Height(25)))
             {
                 StartCoroutine(RefreshHostList());
             }
             
             GUILayout.Space(5);
             
             if(GUILayout.Button("Go Back", GUILayout.Height(25)))
             {
                 iWantToConnectToAServer = false;
             }
             
         }
     }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Host Migration 1 Answer

Internal error while attempting to connect to master server 0 Answers

Client not loading into the same scene as host 0 Answers

Client Disconnect with message “Peer Created” - PUN 0 Answers

A node in a childnode? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges