Skip to main content
Known Participant
March 19, 2010
Question

Reconnect to server on close

  • March 19, 2010
  • 2 replies
  • 2191 views

Hi,

I've been banging my head against the wall for a while with this problem. I'm developing a Flash application that is streaming multiple videos at the same time from Flash Media Server 3.5 over one netConnection. The connection is established when the application is initialized and after that all video player instances use the same netConnection object to connect to the media server. Initially this seemed a better way to do it, than using a separate connection for each videoplayer (I figured it would save some bandwidth even though I wasn't quite sure how much overhead does netConnection add to the stream, if any and how much more or less load does it cause to the mediaserver). It seems to work well when the connection to the server is fast and stable. However on slower and more unstable connections, the netConnection starts breaking up. And new netConnection can't be established in netStatusEvent handler.

So my main problem now is that when the connection is closed, all the streams obviously stop and you'll have reload the application/web page to re-establish the netConnection (not very user friendly). So I've been wondering what my options are. Should I use separated connection for each stream and maybe even start using the FLVPlayback component in Flash instead of the built-in Video class. Or is there some way to reconnect a closed netconnection and resume the streams from where they were left when the connection suddenly closed?

    This topic has been closed for replies.

    2 replies

    March 19, 2010

    Hi teel,

    Are you facing any network glitches which may be affecting you netconnection? We could also check the access.00.log on your fms server to know why the conenctions might be getting dropped from the details logged there. You could enable all the events and fields in access.00.log before you run your test

    In FMS install directory/conf/Logger.xml

    Under the nodes <Logger><Access> modify to <Events>*</Events> & <Fields>*</Fields>

    This will enable all the details. So when you run the test and see the connections getting dropped we might try to find some clue in access.00.log.

    Now if there were really some network glitches and due to which the connections don't end up being stable you could use the new Stream Reconnect feature available in FMS 3.5.3 with Flash Player 10.1.

    With this feature you can make use of the existing netstream objects and attach them to the reconnected netconnection and obtain a seamless playback.

    Check out more details about the feature on http://help.adobe.com/en_US/FlashMediaServer/3.5.3/FeaturesGuide/flashmediaserver_3.5.3_features.pdf

    You could get the FMS 3.5.3 from http://www.adobe.com/support/flashmediaserver/downloads_updaters.html. Flash Player 10.1 is currently in Beta  ( http://labs.adobe.com/downloads/flashplayer10.html ) and will be released soon.

    Thanks

    Mamata

    teel_Author
    Known Participant
    March 19, 2010

    Thanks for your replies. Unfortunately I'm targeting this app for Flash Player 9, so I'm missing some nice features from FP10(.1). This happens almost always on slow connections. I've tested this by limiting my bandwidth to 512kbps with NetLimiter and it disconnects almost immedately when I start streaming the videos (there's 6 simultaneous videos altogether). Our testers have also faced this problem when using unstable/slow network. I guess digging through the logs is my next step, but that'll have wait until next week.

    If I would use the method JayCharles descibes, what would be the best way to handle it with NetStreams? As far as I know, NetStream is closed immediately when NetConnection is lost. If I reconnect the same instance of NetConnection to the same server, does NetStream detect the connection is active again, or do I need to create a new NetStream or manually connect the old NetStream again when connection is established to resume the video from where it was left when the connection closed?

    March 20, 2010

    If you re-connect the same instance of netconnection, you would loose the netstream too. You will have have to create the netstream again and issue the NetStream.play( )once again. It won't resume from where it was playing earlier but you can easily handle this using client-side action script by tracking the NetStream.time property while the stream was being subscribed.

    While the stream was being played, you could store the NetStream.time value into a variable say start_time and keep storing it at periodic intervals. So when the play stops you will roughly have the playtime available in start_time. After the reconnection and netstream creation you could issue NetStream.play(streamname, start_time, -1, true) to begin playing from where it had stopped.

    Let me know if this is what you are looking for.

    Thanks

    Mamata

    March 19, 2010

    I'd continue to use the same netconnection for both streams.

    You're right about the not being able to reestablish the netconnection from within the netstatus handler. What you can do is dispatch another event in your netstatus event handler in response to the NetConnection.Connect.Close status, and let another method or class handle the reconnect.