Only getting "Connecting to Masterserver"

Options
Nyanko
edited September 2013 in DotNet
Hi :)

I'm new to Photon development and I'm trying to get the hang of it. Right now I'm working with the "demo-particle" project that came with the Xamarin component SDK. Installed it on my android test device and it connects with no problems to the master- and gameserver.

My problem is now that I can't get it to work in my own project. I'm pretty sure I forgot something small but after long searching through the code example from above I still couldn't find it. First, here is what I have:

Main Activity
[code2=csharp][Activity (Label = "PlayActivity")]
public class PlayActivity : Activity
{
private GameLogic gameLogic;

protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView(Resource.Layout.Play);

initMatchmaking();
}

private void initMatchmaking()
{
const string serverAddress = "app.exitgamescloud.com:5055";
const string appId = "myID"; // Got it from app page!
const string gameVersion = "1.0";

gameLogic = new GameLogic(serverAddress, appId, gameVersion);
gameLogic.Start();

Thread thread = new Thread(this.test);
thread.IsBackground = true;
thread.Start();
}

private void connectOrCreateRoom()
{
if(!gameLogic.ConnectToRoom(deckType))
{
Console.WriteLine("No rooms available!");

if(!gameLogic.CreateRoom(deckType))
{
Console.WriteLine("Can't create room!");
}
else
{
Console.WriteLine("Created room: " + gameLogic.getCurrentRoom());
}
}
else
{
Console.WriteLine("Joined room: " + gameLogic.getCurrentRoom());
}
}

private void test()
{
while(true)
{
gameLogic.UpdateLoop();

if(gameLogic.Connected == true)
{
connectOrCreateRoom();
break;
}

Thread.Sleep(1);
}
}
}[/code2]

Game Logic
[code2=csharp]public class GameLogic : LoadBalancingClient
{
public bool Connected = false;

public GameLogic(string masterAddress, string appId, string gameVersion) : base(masterAddress, appId, gameVersion)
{
this.LocalPlayer.Name = "usr" + SupportClass.ThreadSafeRandom.Next() % 99;
}

public void Start()
{
if (!this.Connect())
{
this.DebugReturn(DebugLevel.ERROR, "Can't connect. Either server is unavailable or policy doesn't allow it. Server: " + this.MasterServerAddress);
}
}

public void UpdateLoop()
{
if(this.State == ClientState.ConnectedToMaster)
{
Connected = true;
}
}

public bool ConnectToRoom(DeckEnum deckType)
{
// Stuff to connect to a room
}

public bool CreateRoom(DeckEnum deckType)
{
// Stuff to create a room
}
}[/code2]

I hope I went the right way with what I did to this point and I simply overlooked something.

Thanks for looking into it! :)

Comments

  • Tobias
    Options
    Please describe in more detail in which way it goes wrong. You can also check the log to get some hints please.
  • Thanks for you reply Tobias.

    I don't know how to describe more detailed what is going wrong. I simply start my activity and the OnCreate-Method calls everything so Photon would connect to the Masterserver. After the Start-Method in Row 21 I start a new background thread to check if it connected to the Masterserver (In PlayActivity row 49 and in GameLogic row 18). But the code is never leaving the background thread because the GameLogic State is never ClientState.ConnectedToMaster. Its always ClientState.ConnectingToMasterserver.

    Regarding the log, nothing is printed there. Or do you mean a special log from Photon?
  • Tobias
    Options
    Very important: Make sure you call Service() in short intervals. I don't see that in your code.
    Check the demos for it.
    Once you grasped the ideas of it, you can also fine-tune this by calling SendOutgoingCommands() and DispatchIncomingCommands() individually (explained in the doc).
  • I couldn't find the Service() call in the demo I mentioned above but I found SendOutgoingCommands() and DispatchIncomingCommands(). After implementing them its working like a charm. Thanks for helping :)
  • Tobias
    Options
    Ah, you will be right. Service() is the summary of both and more or less there for convenience. Together those methods provide more control and in the demos that's a good show-case.

    Glad you found it.