2 Replies Latest reply on Mar 15, 2010 7:21 AM by Ethan Rom

    Reconnect after disconnect

    Ethan Rom

      When 2 users are connected and there is a disconnection (due to hiccup in internet connection for example), what is the best way to handle a reconnection?


      The goal here is a more seamless experience from the user's point of view.

      (For example most IM clients now will auto-reconnect when hiccups occur)


      I know the following code is part of the solution, but are there best practices for this common situation?



      inNetStream = new NetStream(netConnection, event.info.stream.farID);




        • 1. Re: Reconnect after disconnect
          Ethan Rom Level 1

          Assume a private IM 1-to-1 scenario in which only 2 peers are connected.

          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







          From here, there are a couple options.

          1) If I detect my peer has disconnected, I can try to reconnect to the other peer via  stored farID

          2) If I detect remote peer has disconnected, I can try to reconnect to the other peer via the stored farID



          A potential problem I want to avoid here is both clients trying to reconnect to each other at the same time.



          Note: I am not using NetGroup to avoid security dialog.


          This "hiccup" reconnect seems like it would be a fairly common issue.

          Any help here would be greatly appreciated.

          • 2. Re: Reconnect after disconnect
            Ethan Rom Level 1

            So I have something working that reconnects a disconnected peer.

            I when I detect that my peer has disconnected, I make sure the NetStream is destroyed and no longer in memory.

            The remote peer is set to auto-reconnect when it detects a disconnection using event.info.farID.


            Could someone please confirm best practices for this sort of thing?

            Is this how other people are handling this?