- Home /
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;
}
}
}
Your answer
Follow this Question
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