Cannot join lobby or join/create a room

Options

Hi, I have just started with Photon.

  1. I've created a free Photon app.
  2. I've provided this app id and my app version through injected settings into base LoadBalancingClient class.

It's unclear for me if I should call any kind of "ConnectTo.." servers functions. It gives me true but I can see only one OnStateChange: PeerCreated -> ConnectingToNameServer

Than I'm trying QuickMatch function and I'm getting these errors for JoinLobby and room creation. I have also tried all kind of joinorcreate variations etc.


What do I miss? I want to test room connections, getting/updating players list in every client side and be able to send bytes array to any chosen from them.

Thanks

Filip Zieliński

Best Answer

  • [Deleted User]
    Answer ✓
    Options

    Hi, please make sure you are calling Service periodically, unlike PUN, the realtime application does not call this automatically.

    If you're not using Unity, you can make a new thread, use tasks or just keep it on the main thread:

    public SpookedPhoton(ISpookedSettings settings) 
        : base(string.Empty, appId, appVer, ConnectionProtocol.Udp)
    {
        // Other preceding code...
    
        new Thread(Dispatcher) { IsBackground = true }.Start();
    }
    
    private void Dispatcher()
    {
        while (true)
        {
            try
            {
                while (LoadBalancingPeer.DispatchIncomingCommands()) ;
            }
            catch(Exception e)
            {
                DebugReturn(DebugLevel.ERROR, 
                    $"Unhandled exception while trying to dispatch a command from someone:\n{e}");
            }
            finally
            {
                while (LoadBalancingPeer.SendOutgoingCommands()) ;
            }
    
    
            Thread.Sleep(IsConnected ? 10 : 100);
        }
    }
    

    If you are using Unity, make sure to call LoadBalancingClient.Service() in an Update function. You don't need to make any new threads for Unity.

    If this isn't your issue, you can override DebugReturn to figure out other information about the problem.

Answers

  • [Deleted User]
    edited October 2021
    Options

    Hi, please make sure you are calling Service or the dispatch functions periodically. Service is the LoadBalancingClient function which will dispatch incoming and outgoing commands. If you do not call this function, then no commands will be sent.

    Please consider the following code below:

    public SpookedPhoton(ISpookedSettings settings)
        : base(string.Empty, appId, appVer, ConnectionProtocol.Udp)
    {
        // Other preceding code ...
    
        new Thread(Dispatcher) { IsBackground = true }.Start();
    }
    
    private void Dispatcher()
    {
        while (true)
        {
            try
            {
                while (LoadBalancingPeer.DispatchIncomingCommands()) ;
            }
            catch(Exception e)
            {
                DebugReturn(DebugLevel.ERROR, 
                    $"Unhandled exception while trying to dispatch a command:\n{e}");
            }
            finally
            {
                while (LoadBalancingPeer.SendOutgoingCommands()) ;
            }
    
    
            Thread.Sleep(IsConnected ? 10 : 100);
        }
    }
    

    If you already have a Service implementation running in the background and this isn't the issue, make sure the AppID is correct. If you need any further information you can override the DebugReturn function and it should tell you what's going on.

  • [Deleted User]
    Options

    Hi, please make sure you are calling Service and or the dispatch functions periodically. The realtime framework does not automatically do this for you. PUN however, does do this inside of the PhotonHandler class. If you don't call them, then no commands will be sent. Please consider the following code below.

    If you aren't doing this in Unity, you can use threads or tasks (or you can just keep it on the main thread).

    public SpookedPhoton(ISpookedSettings settings) 
        : base(string.Empty, appId, appVer, ConnectionProtocol.Udp)
    {
        // Other preceding code...
    
        new Thread(Dispatcher) { IsBackground = true }.Start();
    }
    
    private void Dispatcher()
    {
        while (true)
        {
            try
            {
                while (LoadBalancingPeer.DispatchIncomingCommands()) ;
            }
            catch(Exception e)
            {
                DebugReturn(DebugLevel.ERROR, 
                    $"Unhandled exception while trying to dispatch a command from someone:\n{e}");
            }
            finally
            {
                while (LoadBalancingPeer.SendOutgoingCommands()) ;
            }
    
    
            Thread.Sleep(IsConnected ? 10 : 100);
        }
    }
    

    If you are doing this in Unity, you should call LoadBalancingClient.Service() inside of a Unity Update or FixedUpdate function. There is no need to make any new threads in Unity. That will begin sending your commands.

    If you are already calling Service and this is some other issue, make absolutely sure your AppID is correct. You can also override the DebugReturn function to get more information on issues.

  • [Deleted User]
    Answer ✓
    Options

    Hi, please make sure you are calling Service periodically, unlike PUN, the realtime application does not call this automatically.

    If you're not using Unity, you can make a new thread, use tasks or just keep it on the main thread:

    public SpookedPhoton(ISpookedSettings settings) 
        : base(string.Empty, appId, appVer, ConnectionProtocol.Udp)
    {
        // Other preceding code...
    
        new Thread(Dispatcher) { IsBackground = true }.Start();
    }
    
    private void Dispatcher()
    {
        while (true)
        {
            try
            {
                while (LoadBalancingPeer.DispatchIncomingCommands()) ;
            }
            catch(Exception e)
            {
                DebugReturn(DebugLevel.ERROR, 
                    $"Unhandled exception while trying to dispatch a command from someone:\n{e}");
            }
            finally
            {
                while (LoadBalancingPeer.SendOutgoingCommands()) ;
            }
    
    
            Thread.Sleep(IsConnected ? 10 : 100);
        }
    }
    

    If you are using Unity, make sure to call LoadBalancingClient.Service() in an Update function. You don't need to make any new threads for Unity.

    If this isn't your issue, you can override DebugReturn to figure out other information about the problem.

  • [Deleted User]
    Options

    Hi, please make sure you are calling Service and or the dispatch functions periodically. The realtime framework does not automatically do this for you. PUN however, does do this inside of the PhotonHandler class. If you don't call them, then no commands will be sent. Please consider the following code below.

    If you aren't doing this in Unity, you can use threads or tasks (or you can just keep it on the main thread).

    public SpookedPhoton(ISpookedSettings settings) 
        : base(string.Empty, appId, appVer, ConnectionProtocol.Udp)
    {
        // Other preceding code...
    
        new Thread(Dispatcher) { IsBackground = true }.Start();
    }
    
    private void Dispatcher()
    {
        while (true)
        {
            try
            {
                while (LoadBalancingPeer.DispatchIncomingCommands()) ;
            }
            catch(Exception e)
            {
                DebugReturn(DebugLevel.ERROR, 
                    $"Unhandled exception while trying to dispatch a command from someone:\n{e}");
            }
            finally
            {
                while (LoadBalancingPeer.SendOutgoingCommands()) ;
            }
    
    
            Thread.Sleep(IsConnected ? 10 : 100);
        }
    }
    

    If you are doing this in Unity, you should call LoadBalancingClient.Service() inside of a Unity Update or FixedUpdate function. There is no need to make any new threads in Unity. That will begin sending your commands.

    If you are already calling Service and this is some other issue, make absolutely sure your AppID is correct. You can also override the DebugReturn function to get more information on issues.

  • inewland53
    Options

    This worked for me. More specifically calling LoadBalancingClient.Service() in the Unity Update() method.