can't find why client disconnected

Options
lumius
edited July 2012 in Photon Server
DEBUG PhotonIntro.PhotonServer [(null)] - ************************ Send Event ************************
DEBUG Photon.SocketServer.PeerBase [(null)] - SentEvent: ConnID=3, evCode=200, ChannelId=0, result=Ok size=26 bytes
DEBUG PhotonIntro.PhotonServer [(null)] - ************************ Send Event ************************
DEBUG Photon.SocketServer.PeerBase [(null)] - SentEvent: ConnID=3, evCode=200, ChannelId=0, result=Ok size=26 bytes
DEBUG PhotonIntro.PhotonServer [(null)] - ************************ Send Event ************************
DEBUG Photon.SocketServer.PeerBase [(null)] - SentEvent: ConnID=3, evCode=200, ChannelId=0, result=Ok size=26 bytes
DEBUG PhotonIntro.UnityClient [(null)] - ********* Client Response *********
DEBUG PhotonIntro.UnityClient [(null)] - ******************* Receive OK *******************
DEBUG PhotonIntro.PhotonServer [(null)] - ************************ Send Event ************************
DEBUG Photon.SocketServer.PeerBase [(null)] - SentEvent: ConnID=3, evCode=200, ChannelId=0, result=Ok size=26 bytes
DEBUG PhotonIntro.UnityClient [(null)] - ********* Client Response *********
DEBUG PhotonIntro.UnityClient [(null)] - ******************* Receive OK *******************
DEBUG PhotonIntro.PhotonServer [(null)] - ************************ Send Event ************************
DEBUG Photon.SocketServer.PeerBase [(null)] - SentEvent: ConnID=3, evCode=200, ChannelId=0, result=Ok size=26 bytes
DEBUG PhotonIntro.PhotonServer [(null)] - ************************ Send Event ************************
DEBUG Photon.SocketServer.PeerBase [(null)] - SentEvent: ConnID=3, evCode=200, ChannelId=0, result=Ok size=26 bytes
DEBUG PhotonIntro.PhotonServer [(null)] - ************************ Send Event ************************
DEBUG Photon.SocketServer.PeerBase [(null)] - SentEvent: ConnID=3, evCode=200, ChannelId=0, result=Ok size=26 bytes
DEBUG PhotonIntro.UnityClient [(null)] - ********* Client Response *********
DEBUG PhotonIntro.UnityClient [(null)] - ******************* Receive OK *******************
DEBUG Photon.SocketServer.ApplicationBase [(null)] - OnDisconnect - ConnID=3
DEBUG Photon.SocketServer.PeerBase [(null)] - Peer 3 changed state from Connected to Disconnected
DEBUG PhotonIntro.UnityClient [(null)] - client disconnected
3

this is my OnDisconnect function code
for (int i = 0; i < peers.Count; i++)
{
if (!peers.Connected)
{
peers.Dispose();
peers.RemoveAt(i);
}
}

I'm sending event Unreliable true.
client response Unreliable false.


I have some questions
q1. is that disconnection is from server? or client?
q2. why is client disconnected while keep networking?
q3. sometimes sending event result is OK but client status shows disconnected. how can it happen?

Comments

  • Which Photon version do you use? In the Photon 3.0 final release (and in RC9 as well, I think), the PeerBase.OnDisconnect() function has changed to make debugging easier:
    protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)
    {
    // add some debug logging here!
    }
    

    The DisconnectReason is either "ClientDisconnect" (the client closed the connection), "Timeout" (client did not send an ACK(nowledge) in time), "ServerDisconnect" (there had been an exception in Photon's Core - quite unlikely), or "ManagedDisconnect" (the connection was closed by your Photon application (managed .NET code)). That should help you to identify the cause.

    As a side note, I'd change the code a bit:
    - you already know which peer disconnected, so you don't need to iterate through the peer list (probably change the type to List<PeerBase> and call peers.Remove(theDisconnectedPeer)).
    - is "peers" a static member of your Peer class? You need to make it threadsafe - many peers might connect / disconnect and modify the peer collection at the same time. I'd move the peer collection to a separate class, and synchronize all access to the peer collection with fibers, like this:
    class MyPeerCollection()
    {
     private ExitGames.Concurrency.Fibers.PoolFiber fiber; 
     private List&lt;PeerBase&gt; peers = new List&lt;PeerBase&gt;(); 
    
    public MyPeerCollection()
    {
     fiber = new PoolFiber(); 
     fiber.Start; 
    }
    
    OnPeerDisconnected(PeerBase peer)
    {
      this.fiber.Enqueue(() =&gt; 
    {
    if (peers.Contains(peer)) 
    {
    peers.Remove(peer); 
    }
    }); 
    }
    

    (This is pseudo-code, it might not compile - but I hope you get the idea.)

    So, I recommend that you use the new DisconnectReasons to find out why the clients disconnect, and start further investigation from there.
  • lumius
    Options
    thank you for reply. it's very helpful.