Skip to main content
Known Participant
September 22, 2009
Question

Best practices question: multiple or single NetConnection object per application

  • September 22, 2009
  • 1 reply
  • 2799 views

If I'm streaming live video and chatting in an FMS app, should each component have its own instance of NetConnection or should they share one?

Was thinking perhaps the quality of the live video stream would be hurt in a sharing situation but am not sure the architecture works like that.

From a development standpoint, I'd like to make one NetConnection instance in my main application file and connect with it.  Then, when successfully connected, I'd like to pass that connection into any custom components that need it.  Not sure, though, what the best practice is in this regard.

    This topic has been closed for replies.

    1 reply

    calmchessplayer
    Inspiring
    September 22, 2009

    well before fms 3.x the number of connections was a licensing factor but with 3.x w have unlimited connections so i guess you could have multiple netconnection although not many people create an application that way because what if you are passing vaiables to onConnect with 1 connection but not the other i think you would create conflicts with your server side code.....so I must strongly recommend you go with a single NetConnection and just use it for all your ..call,sends,other communication stuff. However it is a good practice that your chat have its own shared object.

    Known Participant
    September 28, 2009

    Appreciate the response.  Yeah that seems to make the most sense.  One NC created by the main application file and then somehow distributed to the app's sub files.  Having a little trouble wrapping my brain around the logistics of the "distributed" NC object though.

    Do I create an NC in the main application file and then call "set" methods on each of my sub files, like this:

    chatPod.setNetConnection(nc);

    slideDec.setNetConnection(nc);

    videoPod.setNetConnection(nc);

    Or do I somehow pass them into constructors for each of the sub files?  Although the sub objects are created in mxml so there really are no constructors per se.

    Or do I maybe extend NetConnection and make it a singleton class?  Each sub file could then ask the singleton class to create a NetConnection or return an instance of one if it already exists?  Problem with that is that whoever creates the first instance, like say the chat, won't handle all of the unique initialization actions required by the other two components (slide dec and video).  So something doesn't quite feel right about the singleton NetConnection class scenario.

    The question has impications about the path of callbacks from FMS to each of the individual components in my app.  In most simple apps, the FMS makes callbacks directly on the app's main application file.  I was thinking my main app would receive the FMS callbacks and then  pass the calls along to methods in each of the sub component files.

    Am I getting warm?

    calmchessplayer
    Inspiring
    September 28, 2009

    I don't use flex so i can't give you advice on how to structure your document....Sorry.