Skip to main content
July 7, 2011
Answered

NetConnection.close() not closing the connection

  • July 7, 2011
  • 1 reply
  • 1546 views

Hello,

I give up. I'm creating a very, very basic AIR application which mainly just needs to check if a given FMS is up and running.

To do that, I'm simply connecting to the FMS and after a successful connection, disconnecting to free up the connection slots. All is repeated at some interval. This is like a monitoring tool.

However, looking into the admin panel (Influxis) I can see that the number of active connections is ever growing, even though I'm calling close() on the NetConnection instance every time.

Also, adding a timer to trace the netConnection.connected value outputs always "true", after the close() function has been called.

I'm not creating any NetStreams, nothing.

The only way to free up the connections for me is to completely close the application.

Any ideas?

Thanks in advance.

    This topic has been closed for replies.
    Correct answer SE_0208

    sure, there it goes:

    http://www.sendspace.com/file/7d8uj3

    To test it, you'll need to enter some working FMS server and app address.

    And here's the actual output I'm getting when connecting to my FMS server:

    connected: false

    connected: false

    --------- FMS ---------

    NetConnection.Connect.Success

    -----------------------

    connection success

    closing connection

    connected: true

    connected: true

    connected: true

    connected: true

    connected: true

    connected: true

    connected: true

    connected: true

    connected: true

    connected: true

    Thanks a lot for helping me investigate it.


    var nc : NetConnection = new NetConnection();
    nc.addEventListener(NetStatusEvent.NET_STATUS, handleNetStatus);
    nc.connect(serverURL);
     
     
    private function handleNetStatus(event : NetStatusEvent) : void
    {     
         trace(event.info["code"]);
         switch(event.info["code"])
         {
              case "NetConnection.Connect.Success":
                   trace("closing");
                   nc.close();
              break;
         }
     
    }

    The problem here is directly calling nc.close() when you get NetConnection.Connect.Success. When you do this i am guessing something is goign wrong. Do one thing, introduce a small timer i.e. call some function once you get sucess after timer of say 2 seconds and inside that function call nc.close() - that should work

    1 reply

    Participating Frequently
    July 7, 2011

    Do you get NetConnection.Connect.Closed after you do NetConnection.close() ?

    July 7, 2011

    No, I don't.

    It's like:

    var nc : NetConnection = new NetConnection();

    nc.addEventListener(NetStatusEvent.NET_STATUS, handleNetStatus);

    nc.connect(serverURL);


    private function handleNetStatus(event : NetStatusEvent) : void

    {     

         trace(event.info["code"]);

         switch(event.info["code"])

         {

              case "NetConnection.Connect.Success":

                   trace("closing");

                   nc.close();

              break;

         }

    }

    And I'm always getting:
    1. NetConnection.Connect.Success

    2. closing

    and then nothing. No NetConnection.Connect.Closed or anything like this.

    Also, querying nc.connected in a timer handler always outputs "true"

    Thanks.

    Participating Frequently
    July 7, 2011

    Can you pass me the full code of your App?