Stuck on ConnectingToNameServer
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on Realtime.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
Stuck on ConnectingToNameServer
Hotshot10101
2015-12-29 23:17:13
I am just starting my first turn based game using Photon Network.
I downloaded the SDK for Unity (5) and am following the getting start intro page.
It seemed to work for a little bit. I was able to create a room and I saw it show up in the statistics page.
It was showing one room and 2 ccu.
Now whenever I run my app either in the Unity Editor or on my iPhone I am getting stuck in a state of ConnectingToNameServer.
I don't know if it was always doing that or not because before when it was working I was not logging what state the system was in.
When it stopped working that is when I added in my logging code to see what was happening.
Here is my whole script (PhotonEventHandler is derived from LoadBalancingClient and sends all events to my GameManagerScript which is below:
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using ExitGames.Client.Photon.LoadBalancing;
using ExitGames.Client.Photon;
public class GameManagerScript : MonoBehaviour
{
static public string PhotonAppId = "removed for privacy in posting to this forum, but is valid";
private PhotonEventHandler _client;
static private GameManagerScript _instance;
static public GameManagerScript Instance
{
get
{
if (_instance == null)
_instance = new GameManagerScript ();
return _instance;
}
}
private float _timeout = 0f;
private float _resetTimeout = 0f;
public GameObject CreateButton;
public GameObject JoinButton;
public GameObject TurnButton;
public GameObject LeaveButton;
public void EnableButton (string button, bool active)
{
switch (button)
{
case "All":
CreateButton.SetActive (active);
JoinButton.SetActive (active);
TurnButton.SetActive (active);
LeaveButton.SetActive (active);
break;
case "Create":
CreateButton.SetActive (active);
break;
case "Join":
JoinButton.SetActive (active);
break;
case "Turn":
TurnButton.SetActive (active);
break;
case "Leave":
LeaveButton.SetActive (active);
break;
}
}
// Use this for initialization
void Start ()
{
_instance = this;
EnableButton ("All", false);
_client = new PhotonEventHandler ();
_client.AppId = PhotonAppId;
if (_client.ConnectToRegionMaster ("us"))
{
EnableButton ("Create", true);
EnableButton ("Join", true);
}
}
public void DebugReturn (DebugLevel level, string message)
{
Debug.Log (string.Format ("{0} - {1} - {2}", "DebugReturn", level.ToString (), message));
}
public void OnOperationResponse (OperationResponse operationResponse)
{
Debug.Log (string.Format ("{0} - {1}", "OnOperationResponse", operationResponse.ToStringFull ()));
}
public void OnStatusChanged (StatusCode statusCode)
{
if (statusCode == StatusCode.Connect)
{
_resetTimeout = 1f;
_timeout = 1f;
}
Debug.Log (string.Format ("{0} - {1}", "OnStatusChanged", statusCode.ToString ()));
}
public void OnEvent (EventData eventData)
{
Debug.Log (eventData.ToStringFull ());
}
// Update is called once per frame
void Update ()
{
_client.Service ();
if (_timeout > 0f)
{
_timeout -= Time.deltaTime;
if (_timeout <= 0f)
{
if (_resetTimeout > 0f)
_timeout = _resetTimeout;
Debug.Log ("State: " + _client.State.ToString ());
}
}
}
void OnApplicationQuit ()
{
_client.Disconnect ();
}
public void OnCreate ()
{
if (_client.IsConnectedAndReady)
{
EnableButton ("All", false);
if (_client.OpCreateRoom ("Shatalmic - TurnBasedTest", new RoomOptions (), TypedLobby.Default))
{
EnableButton ("Turn", true);
EnableButton ("Leave", true);
}
else
{
Debug.Log ("Create room failed");
EnableButton ("Create", true);
EnableButton ("Join", true);
}
}
else
Debug.Log ("Cannot Create: " + _client.State.ToString ());
}
public void OnJoin ()
{
if (_client.IsConnectedAndReady)
{
EnableButton ("All", false);
if (_client.OpJoinRoom ("Shatalmic - XYZ"))
{
EnableButton ("Turn", true);
EnableButton ("Leave", true);
}
else
{
Debug.Log ("Join room failed");
EnableButton ("Create", true);
EnableButton ("Join", true);
}
}
else
Debug.Log ("Cannot Join: " + _client.State.ToString ());
}
public void OnTurn ()
{
if (_client.IsConnectedAndReady)
{
Debug.Log ("turn");
}
}
public void OnLeave ()
{
if (_client.IsConnectedAndReady)
{
EnableButton ("All", false);
EnableButton ("Create", true);
EnableButton ("Join", true);
if (!_client.OpLeaveRoom ())
Debug.Log ("leave room failed");
}
}
}
Comments
One way to check if its an app problem or internet problem. Is to download photon server and use the load balancing app. Its pretty much exactly like photon cloud.
Something with your pun also might have gotten messed up. The connect to master server state is kind of automagical and shouldnt really require much from you.
Take a new scene, and put an empty game object in the sene. Attach the script "connect and join random" in the photon ulitiy scripts folder. Start the scene and see if you still have problems. If you do it might be a connection problem and not a code problem.
Hotshot10101
2022-11-08 16:16:15
I ended up not moving forward with this project, but wanted to thank you (very late) for your reply.
Back to top