Analyze disconnects

qazqaz
edited March 2014 in Flash (deprecated)
Hello,
I need to display disconnect message in flash client as fast as possible when disconnect occurs.
Right now it shows up message about 15 secs later.
What parameters do I need to set?

Comments

  • Hi,
    I'm afraid that flash socket does not have such parameter.
    If you are joined room, you can ping server and disconnect yourself if no reply for certain period of time. Like this:
    [code2=as3]public class MyLoadbalancingClient extends LoadBalancingClient
    {
    ...
    private var disconnectTimer: uint = 0;
    private function ping(): void {
    this.raiseEvent(111, null, { targetActors: [this.myActor().actorNr] } );
    disconnectTimer = setTimeout(disconnect, 5000);
    }
    override protected function onEvent(code:int, content:Object, actorNr:int):void {
    switch (code) {
    case 111:
    trace("ping ack");
    clearTimeout(disconnectTimer);
    setTimeout(ping, 1000);
    break;
    ...
    }
    }
    ...
    }[/code2]Call ping() right after joining the room.
  • Well, photon flash skd (3.2.1.4) has own ping timer with interval of 1000ms, which by the way sends ping only once (on connect) and stops (can't figure out why), and then sends ping on disconnect.
    Is it a bug? or it is intended to be like this.
    Also when the ping is sent, it goes as RaiseEvent Operation on server (253) with sub-code 249 for ping. This on the other hand sends ping event from server to all connected clients. So sould it be like this or ping must go directly as 249 from client so only sender gets back response?
  • Client sends ping message automatically each second while connected to server. Without that ping, if no nothing else is sent from client, server drops connection. Note: this is not RaiseEvent but internal Photon packet. In current sdk state built-in ping can't be used for disconnection diagnosis by end user.
    qaz wrote:
    Also when the ping is sent, it goes as RaiseEvent Operation on server (253) with sub-code 249 for ping...
    What ping do you mean? I can suppose only RaiseEvent ping from my code above. Then I don't see any 249 code there (253 is for RaiseEvent). That ping event is sent only to client itself, note raiseEvent option targetActors: [this.myActor().actorNr].
  • Decompiled PhotonCore.swc
    On init ping timer is initialized:
    [code2=as3]case CoreConstants.MSG_TYPE_INIT_RESPONSE:
    {
    this.debug("*** connection initialized - InitializeConnectionResponse ***");
    if (this._socketBuffer.bytesAvailable)
    {
    this._socketBuffer.readByte();
    }
    this._connectionInitialized = true;
    dispatchEvent(new InitializeConnectionResponse(InitializeConnectionResponse.TYPE));
    this.startPingTimer();
    break;
    }[/code2]
    Which as I said sends ping only once.

    Scratch from Lite Application | LiteGame.cs
    [code2=csharp]protected override void ExecuteOperation(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
    {
    try
    {
    base.ExecuteOperation(peer, operationRequest, sendParameters);

    if (Log.IsDebugEnabled)
    {
    Log.DebugFormat("Executing operation {0}", (OperationCode)operationRequest.OperationCode);
    }

    switch ((OperationCode)operationRequest.OperationCode)
    {
    case OperationCode.Join:
    {
    break;
    }

    case OperationCode.Leave:
    {
    break;
    }

    case OperationCode.RaiseEvent:
    {
    var raiseEventOperation = new RaiseEventRequest(peer.Protocol, operationRequest);
    if (peer.ValidateOperation(raiseEventOperation, sendParameters) == false)
    {
    return;
    }

    raiseEventOperation.OnStart();
    this.HandleRaiseEventOperation(peer, raiseEventOperation, sendParameters);
    raiseEventOperation.OnComplete();
    break;
    }

    case OperationCode.GetProperties:
    {
    break;
    }

    case OperationCode.SetProperties:
    {
    break;
    }

    case OperationCode.Ping:
    {
    peer.SendOperationResponse(new OperationResponse { OperationCode = operationRequest.OperationCode }, sendParameters);
    break;
    }

    case OperationCode.ChangeGroups:
    {
    break;
    }
    default:
    {
    string message = string.Format("Unknown operation code {0}", (OperationCode)operationRequest.OperationCode);
    peer.SendOperationResponse(
    new OperationResponse { OperationCode = operationRequest.OperationCode, ReturnCode = -1, DebugMessage = message }, sendParameters);

    if (Log.IsWarnEnabled)
    {
    Log.Warn(message);
    }
    }

    break;
    }
    }
    catch (Exception ex)
    {
    Log.Error(ex);
    }
    }[/code2]

    As you see here, RaiseEvent And Ping operations are handled difeerently, that's what I meant.

    So why can't that "internal ping" be used to analyze disconnect? And how does it send events every second, I see nothing in server logs. Only one RaiseEvent after connecting.
  • As you see here, RaiseEvent And Ping operations are handled difeerently, that's what I meant.
    Sure. May be I chose wrong name for operation in my sample. It has nothing to do with built-in ping
    So why can't that "internal ping" be used to analyze disconnect?
    Because client api has no appropriate methods.
    And how does it send events every second, I see nothing in server logs. Only one RaiseEvent after connecting.
    I suppose that ping is not logged. Raise log level in server config or in case you have access to server sources, add log to 'case OperationCode.Ping' branch.
  • Looks like OperationCode.Ping is 3rd 'ping' instance in discussion. It's just a Lite operation with code 249. But flash client never uses it internally.
    Client custom code can use this operation instead of RaiseEvent. It's even preferable since it's replied to sender directly without setting target client.
Sign In or Register to comment.