Skip navigation
Currently Being Moderated

How to detect if any peer gets disconnected

Mar 6, 2010 5:23 AM

Hi,

When a subsribing peer tries to connect to the publishing peer to play the stream, the callback method "onPeerConnect" is executed automatically. But what if any peer (i.e. publishing or subscribing) gets disconnected due to any reason? is there any callback function that is triggered automatically in that case also?

 

Thanks in advance.

 
Replies
  • Currently Being Moderated
    Mar 6, 2010 10:51 AM   in reply to Authentic Sols

    I had your same problem & this is how I solved it:

     

    Once the application is activated, each client (SWF) makes a call to the database every 10 seconds (you can decide your own timeframe) & updates their record with a fresh timeStamp. If the client stops making calls to the database, the timeStamp gets old & is cleared out by another job that runs every few minutes (you can decide your own timeframe) if its timeStamp is older than 2 minutes.

     

    This has been very effective for me & my team to keep an accurate listing of active user IDs.

     

    Hope this helps,

    RGB

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 6, 2010 1:15 PM   in reply to RGBEFFECTS

    I've also been working on disconect detection and reconnection (where possible).

    I hope there's a way to detect a disconnect using only stratus.

     

    Here's what I have so far and I hope someone else can shed more light on this.

     

    It looks like a couple events get fired when a disconnect happens.

     

    NetStream.Connect.Closed

    if you have this set you will see it ...

    netConnection.addEventListener(NetStatusEvent.NET_STATUS,blahlbah

     

    and

     

    NetStream.Play.UnpublishNotify

    seems to fire when other peer's outNetStream closes

     

    I hope someone from Adobe can give us more info.

    A user disconnect event is about as basic as it gets for this kind of stuff.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 6, 2010 1:58 PM   in reply to Authentic Sols

    Hi,

     

    you need to use the netstatus listener on the netconnection.

     

    "NetStream.Connect.Closed" is fired on disconnection.

     

    You can than check the farID with  -   info.stream.farID.

     

    You can also check if the netstream is the correct one by comparing the clients   -   if(event.info.stream.client==NetStrm.client){}

     

     

     

     

     

    netconnection.addEventListener(NetStatusEvent.NET_STATUS,OnStreamStatu s,false,0,true)

     

    NetStrm = new NetStream(netconnection,peerid)

     

    public function OnStreamStatus(event:NetStatusEvent):void

    {

     

     

     

         if(event.info.code=="NetStream.Connect.Closed")

         {

              if(event.info.stream.client==NetStrm.client)

              {

                   CurrentPeerId = data.info.stream.farID

                   dispatchEvent(OnDisconnected)

              }

     

         }

     

     

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 6, 2010 5:18 PM   in reply to Mahron

    That is how I'm doing it too.

    However it seems to be unreliable since sometimes after that event fires the two peers are still connected and can still send messages to each other.

     

    For me it means that the peer "might" have disconnected so I need to ping it.

     

    Does anyone know why that would fire that event when the peers are still connected?

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 7, 2010 1:47 AM   in reply to Ethan Rom

    Are you 100% sure that it is the correct netstream(with the farid of one of the  two peers) which is disconnected and not an other one using the same netconnection ?

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 8, 2010 6:14 AM   in reply to Mahron

    Mahron is right.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 8, 2010 4:05 PM   in reply to FMSer.cn

    yes.  Mahron is correct.

     

    a NetStream.Connect.Closed NetStatusEvent.NET_STATUS event will be dispatched to the NetConnection.  event.info.stream will be the per-peer sub-NetStream for the specific peer that disconnected.  event.info.stream.farID is the peerID of that peer.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 12, 2010 9:29 AM   in reply to Michael Thornburgh

    Here's is more detailed disconnection info I've found to work anecdotally.

    Could someone from Adobe please confirm that this is correct.

    I think this kind of disconnect/reconnect info should be in the NetStream/NetConnetion docs/tuts.

     

     

    Each peer has an inStream and an outStream, I can detect the following 4 disconnection events:

    a) My Peer's inStream has disconnected  : onInNetStreamStatus NetStream.Play.Stop

    b) My Peer's outStream has disconnected : onOutNetStreamStatus NetStream.Play.Stop

    c) Remote Peer's inStream has disconnected   :  onNetConnectionStatus NetStream.Connect.Closed //if(event.info.stream != inNetStream

    d) Remote Peer's outStream has disconnected  : onNetConnectionStatus NetStream.Connect.Closed //if(event.info.stream == inNetStream

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points